Ok, die verwende ich auch. Ich habe gerade mal einen Test mit einer DB bei meinem Provider gemacht, das funktioniert mit diesem Sketch:
#include <ESP8266WiFi.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
WiFiClient client; // Use this for WiFi instead of EthernetClient
MySQL_Connection conn(&client);
MySQL_Cursor* cursor;
// <= 31 Zeichen
const char *ssid = "wlanSSID";
// >= 8 oder <= 63 Zeichen oder NULL
const char *password = "wlanPwd";
char stmt[256];
char dbuser[] = "DB-Username"; // MySQL user login username
char dbpassword[] = "DB-Passwort"; // MySQL user login password
char db[] = "Datenbankname"; // DB-Name
uint32_t lastMillis;
void setup() {
int counter = 0; // Counter für Verbindung zum WLAN
Serial.begin(115200);
Serial.println("\nStart");
WiFi.persistent(false);
// Betrieb als Station
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay (500);
Serial.print(".");
counter++;
if (counter > 100) {
Serial.println("Kein WLAN. Restart!");
ESP.restart();
}
}
Serial.print("\nConnected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
IPAddress remote_addr;
if (WiFi.hostByName("DB-Server-name", remote_addr)) {
Serial.print("Remote-DB: ");
Serial.println(remote_addr);
}
Serial.println("\nConnecting to database . . .");
if (conn.connect(remote_addr, 3306, dbuser, dbpassword)) {
Serial.println("DB-Connection ok.");
delay(500);
}
else {
Serial.println("DB-Connection failed.");
delay(10000);
ESP.restart();
}
}
void loop() {
}
Das ergibt ein:
.......
Connected to ......
IP address: 192.168.178.28
Remote-DB: 178.254.0.226
Connecting to database . . .
...trying...
Connected to server version 5.7.24-0ubuntu0.18.04.1-log
DB-Connection ok.
Gruß Tommy
Edit: Ich habe gerade eine lokale DB angelegt, damit läuft es auch.