send Arduin integer number with esp8266 to mysql

Asked

Viewed 219 times

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:

inserir a descrição da imagem aqui

I don’t know where I’m going wrong, I’ve done research and that’s the only way it appears.

  • 2

    Your sql is going through %d however no value.

  • 1

    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')

  • 2

    Do not use text images. They are too bad to read...

  • how can I then pass the value of the variable number?

  • Look that link can help you

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.