I don't know how to tell but I will try :)
I am using NodeMCU and CAM module, CAM module read the QR code and user 1 get the link like this: sitename.com/project/userid1
For example another user 2 have sitename.com/project/userid2 link. And CAM module send to link by string to the NODEMCU I did this step.
NODEMCU can connect this link to the internet. Main question is how can I do this:
When the user logs in from a specific address for example user 1 get sitename.com/project/userid1 link. How to reduce the balance of user1 (defined in the database)? So I can do a transaction in the database with the information I came from any link. How can the site know how I come from that link ?
Please help me.
EDIT 1
I decide to send just ID for user, for the userid1 send to 1, userid2 send to 2 ... When I get the "1" I want to go ID=1 user and get the user1's balance.
So, that's the new question. When I connect with nodemcu to MYSQL, how can I get the balance value (this is table users' member) and how to send balance=balance-1 value to MYSQL ?
How to add this code to 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
This is my some code: (How can add part of mysql get value and send value)
#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
}