Ich versuche inzwischen seit drei Stunden verzweifelt einen direkten Datenbank INSERT mit dem NodeMCU v3 und dem MySQL Connector. Als Basis habe ich den Beispiel Sketch "basic_insert_esp8266" genommen. Leider bekomme ich immer ein Timeout beim Schreiben in die Datenbank.
Connected to network
My IP address is: 192.168.178.170
Connecting to SQL... ...trying...
ERROR: Timeout waiting for client.
Error: -1 = FAILED.
Dies passiert sowohl beim Verbinden mit der mysql Datenbank auf meinem Qnap als auch über xampp auf meinem PC. Der INSERT selbst scheint soweit in Ordnung und wurde per SQL direkt in der Datenbank geprüft. Ich hoffe ihr habt noch eine Idee, wo ich ansetzen kann.
Hier noch der Code:
#include <ESP8266WiFi.h> // Use this for WiFi instead of Ethernet.h
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
IPAddress server_addr(192,168,178,10); // IP of the MySQL *server* here
char user[] = "arduino"; // MySQL user login username
char password[] = "heutrocknung"; // MySQL user login password
// Sample query
char INSERT_SQL[] = "insert into tbl_Sensoren (id, temperatur, druck, luftfeuchtigkeit, sensor, node, Timestamp) values(NULL, '1', '2', '3', 'BMP280', '1', now())";
// WiFi card example
char ssid[] = "WLAN"; // your SSID
char pass[] = "PASS"; // your SSID Password
WiFiClient client; // Use this for WiFi instead of EthernetClient
MySQL_Connection conn(&client);
MySQL_Cursor* cursor;
void setup()
{
Serial.begin(115200);
while (!Serial); // wait for serial port to connect. Needed for Leonardo only
// 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.print("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);
}