ChuckBell / MySQL_Connector_Arduino

Database connector library for using MySQL with your Arduino projects.
331 stars 132 forks source link

On regard issue 42 #98

Closed jorgher closed 2 years ago

jorgher commented 5 years ago

Reading all issues related found that there is something different with the one I sent.

  1. I'm using ESP8266 and Wemos D1 mini with the same sketch Figure 1.
  2. Using the SQL user with all privileges see Figure 2 and when running,
  3. the serial window show that there is a connection with SQL Figure 1, but there is a different message from the one in the manual. Where the library respond with the version of the SQL

    Figure1 Figure2

besides that I modify the sketch see below;

/* Using Ethernet*/

#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include "DHT.h"
#include "Ethernet.h"

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; 
EthernetClient client;
MySQL_Connection conn((Client *)&client);
IPAddress serv_addr(192,168,0,50);  // MySQL server IP
char user[] = "jorge";         // MySQL user
char passwd[] = "pass";       // MySQL passwor
char INSERT_DATA[] = "INSERT INTO valores (sensID, tempC, tempF, humedad) VALUES ( 'oficina','22','87','65' )";

void setup() {
  Serial.begin(115200);
  while (!Serial);
  Ethernet.begin(mac_addr);
  Serial.println(" Conectando a SQL ....");
  if (conn.connect(serv_addr, 3306, user, passwd) != true) {
    delay(1000);
    Serial.println("");
    Serial.print ( "Conectada" );

  }
  else {
    Serial.println ("connection failed");
    conn.close();
  }

}

void loop() {
  //Registrando datos
  delay(2000); 
  MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
  cur_mem->execute(INSERT_DATA);
  Serial.println("Se registro entrada");

  delete cur_mem;
}
}

when running (notice that in this is used Ethernet library) have a connection and a series of data input messages, see Figure 3, but when checking table from mariaDB there were no input in table Figure 4.

Figure3

Figure4

jorgher commented 5 years ago

The message from the manual in page 9 is:

Connecting... Connected to server version 5.7.9-log Query Success!

ChuckBell commented 5 years ago

First, the reason you are not seeing a similar message as shown in the manual on connection is because you are not using MySQL. Specifically, you are using a non-Oracle maintained variant. This variant is known to differ from Oracle MySQL and because of those differences, the connector is not guaranteed to work with non-Oracle MySQL variants. That said, some have had great success, but officially it is not supported. I suggest you install Oracle's MySQL and try it with that. You should see a similar response on connection.

Second, you said you're using an ESP8266 and a Wemos. Perhaps I read something or am misunderstanding, but aren't both of these WiFi? In that case, using the Ethernet library isn't going to work. Frankly, I'm amazed you did not see any errors in your sketch. I suggest you use the ESP8266WiFi class in your sketch connecting first to your WiFi and then to MySQL (Oracle's MySQL).

Debugging issues like these are always best done with a set of known working configuration items. In this case, the connector does work with ESP8266 using the ESP8266WiFi library and Oracle's MySQL. Variations on that theme may not have the same results.

ChuckBell commented 5 years ago

Also, you should check the return code from the query. It may give you a clue if there are any error messages. You can do this in a number of ways, but the easiest is to check to see if the execute() returns False, which means the query failed. So, your sketch isn't checking for that condition and thus it may seem like the query is working. A deeper dive would require modifying the connector code directly to print out the return packet from the server - something that may appear in a future release, but for now you can do it manually - ask me for the details if you want to go this route. However, adding the if statement for the execution should be enough.

ChuckBell commented 2 years ago

Closed due to inactivity. Please open a new ticket if this is still relevant.