1
I have an error when I send via ESP8266, the integer value with the name number, my code is as follows:
#include <ESP8266WiFi.h> // Use this for WiFi instead of Ethernet.h
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
// WiFi card example
**a conexão á minha rede funciona **
char ssid[] = "xxxxxxxxxxxx"; // your SSID
char pass[] = "xxxxxxxxxxxx"; // your SSID Password
IPAddress server_addr(192,168,43,175); // IP of the MySQL *server* here
char user[] = "root"; // MySQL user login username
char password[] = "admin"; // MySQL user login password
int numero = 10;
// Sample query
char INSERT_SQL[] = "INSERT INTO MQTT.TESTES (numero) VALUES (%d)";
WiFiClient client; // Use this for WiFi instead of EthernetClient
MySQL_Connection conn(&client);
MySQL_Cursor* cursor;
void setup()
{
Serial.begin(115200);
// Begin WiFi section
Serial.printf("\nConnecting to %s", ssid);
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
// print out info about the connection:
Serial.println("\nConnected to network");
Serial.print("My IP address is: ");
Serial.println(WiFi.localIP());
Serial.println("Connecting to SQL... ");
if (conn.connect(server_addr, 3306, user, password))
Serial.println("OK.");
else
Serial.println("FAILED.");
// create MySQL cursor object
cursor = new MySQL_Cursor(&conn);
}
void loop()
{
if (conn.connected())
cursor->execute(INSERT_SQL);
delay(5000);
}
The error you give me is this, when I run the code on ESP8266:
I don’t know where I’m going wrong, I’ve done research and that’s the only way it appears.
Your sql is going through
%d
however no value.– Pedro Augusto
The
%d
that’s going through your query should refer to a whole, as quoted, but has no value, so the syntax error (you have an error in your SQL sintax; .. syntax to use near '%d')– Tuxpilgrim
Do not use text images. They are too bad to read...
– Leonardo Alves Machado
how can I then pass the value of the variable number?
– Sergio Nunes
Look that link can help you
– Pedro Augusto