MySQL_Connector_Arduino
MySQL_Connector_Arduino copied to clipboard
Can't Connect with ESP8266
I am having an issue connecting with my ESP8266 but using the same code no issue with an ESP32 except for ESP8266WiFi.h for ESP8266 and WiFi.h for ESP32
below is my code for the ESP8266:
#include <ESP8266WiFi.h> // Use this for WiFi instead of Ethernet.h
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
IPAddress server_addr(192,168,2,219); // IP of the MySQL *server* here
char user[] = "espUser"; // MySQL user login username
char password[] = "password"; // MySQL user login password
// WiFi card example
char ssid[] = "ROCKv2"; // your SSID
char pass[] = "password"; // your SSID Password
WiFiClient client; // Use this for WiFi instead of EthernetClient
MySQL_Connection conn((Client *)&client);
void setup() {
Serial.begin(115200);
while (!Serial); // wait for serial port to connect. Needed for Leonardo only
WiFi.begin(ssid, pass);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.println(".");
}
Serial.println("Connected to network");
Serial.print("My IP address is: ");
Serial.println(WiFi.localIP());
Serial.println("Connecting...");
if (conn.connect(server_addr, 3306, user, password)) {
delay(1000);
}
else
Serial.println("Connection failed.");
conn.close();
}
void loop() {
}
I get the following output
My IP address is: 192.168.2.53
Connecting...
...trying...
ERROR: Timeout waiting for client.
Error: -1 = Connection failed.
Does anyone have any idea why this would not work but work on an ESP32?
What version of the ESP library are you using? Version 3.0 has a known issue. If you can downgrade to 2.7.4, it should work. See issue#185.