我不知道该怎么讲,但我会尝试:)
我正在使用NodeMCU和CAM模块,CAM模块读取QR码,用户1会获得如下链接:sitename.com/project/userid1
例如,另一个用户2具有sitename.com/project/userid2链接。然后CAM模块通过字符串发送到NODEMCU的链接,我完成了这一步。
NODEMCU可以将此链接连接到Internet。 主要问题是我该怎么做:
当用户从特定地址登录时,例如,用户1获得sitename.com/project/userid1链接。如何减少user1(在数据库中定义)的余额? 因此,我可以使用来自任何链接的信息在数据库中进行事务处理。该网站如何知道我从那个链接来的消息?
请帮助我。
编辑1
我决定只为用户发送ID,将userid1发送给1,将userid2发送给2 ...当我得到“ 1”时,我想成为ID = 1的用户并获得user1的余额。
所以,这是新问题。当我将nodemcu连接到MYSQL时,如何获取余额值(这是表用户的成员)以及如何将balance = balance-1值发送到MYSQL?
如何将此代码添加到arduino
UPDATE users SET balance=balance_new WHERE id = readx
readx come 1,2,3,.. to the CAM module
users name the mysql table
balance is the member of the users
这是我的一些代码:(如何添加部分mysql获取值和发送值)
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
int balance;
const char* ssid = "ssid";
const char* password = "pas";
IPAddress server_addr(xx, xx ,xx, x); // MySQL server IP
char user[] = "sitename_user"; // MySQL user
char password[] = "pass"; // MySQL password
void setup () {
Serial.begin(19200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.print("Connecting..");
}
while (conn.connect(server_addr, 3306, user, password) != true) {
delay(200);
Serial.println("Connecting SQL..");
}
Serial.println("Connected SQL..");
}
void loop() {
if(Serial.available()>0) //Checks is there any data in buffer
{
String readx=Serial.readString();
Serial.print(readx); //Read serial data byte and send back to serial monitor
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
//Get the request response payload
HTTPClient http; //Declare an object of class HTTPClient
http.begin(readx); //Specify request destination
int httpCode = http.GET(); //Send the request
if (httpCode > 0) { //Check the returning code
String payload = http.getString();
//Print the response payload
}
http.end(); //Close connection
}
}
delay(30000); //Send a request every 30 seconds
}