Closed Zane1996 closed 2 years ago
Hi,
Yep. The IP address of the server is incorrect. You need the external IP address of the server where MySQL is running. 127.0.0.1 is the loopback address. Won’t work. :)
Dr. Bell
On Thu, Jul 18, 2019 at 18:26 Zane1996 notifications@github.com wrote:
Hi, I am using an ESP32 so I had to modify the MySQL_Packet_h file to allow use of the MySQL connector, however the serial monitor gets stuck on "Connecting to SQL..". Have any idea as to what would cause this? I'll post the code below.
[code]
include
include
include
IPAddress server_addr(127,0,0,1); // IP of the MySQL server here char user[] = "root"; // MySQL user login username char password[] = ""; // MySQL user login password
// Sample query char INSERT_SQL[] = "INSERT INTO data (sensor,location,value1,value2,value3) VALUES ('Thermocouple', 'office', 20, 20, 20)";
// WiFi card example char ssid[] = ""; // your SSID char 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); } [/code]
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/105?email_source=notifications&email_token=AB6SHYBMPCPXMWYHZMGWJI3QADU2NA5CNFSM4IFAFYW2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HAD5WEQ, or mute the thread https://github.com/notifications/unsubscribe-auth/AB6SHYEROQUYPIM5MO5CUTTQADU2NANCNFSM4IFAFYWQ .
Where would I find the external IP address? Sorry I'm very new to this.
Depends on the OS. If Linux or macOS, run ifconfig. If Windows, run ipconfig /all. Look for the interface you’re using - typically WiFi.
On Thu, Jul 18, 2019 at 18:31 Zane1996 notifications@github.com wrote:
Where would I find the external IP address? Sorry I'm very new to this.
— You are receiving this because you commented.
Reply to this email directly, view it on GitHub https://github.com/ChuckBell/MySQL_Connector_Arduino/issues/105?email_source=notifications&email_token=AB6SHYFCGSSZILCJPSH4ZHLQADVLBA5CNFSM4IFAFYW2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD2J7N6I#issuecomment-513013497, or mute the thread https://github.com/notifications/unsubscribe-auth/AB6SHYH3VNIMPCTDZWPWULTQADVLBANCNFSM4IFAFYWQ .
I added the IP address and it is still stuck at "Connecting to SQL...". Could it be something else?
Yes. Check the manual. It can be permissions, password, firewall, network, etc. There are suggestions on how to diagnose in the manual.
On Jul 18, 2019, at 6:40 PM, Zane1996 notifications@github.com wrote:
I added the IP address and it is still stuck at "Connecting to SQL...". Could it be something else?
— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.
I had the same problem on my Wemos D1 mini PRO, and after some debugging I ended up commenting out MYSQL_Packet.cpp, lines 292-296. like this:
/*int avail_bytes = wait_for_client(); while (avail_bytes < 4) { avail_bytes = wait_for_client(); Serial.print("Waiting for 4 avail bytes.Currently we have: "); Serial.println("avail_bytes"); } */
I would suggest to implement these changes for all ESP8266 chips. I always got stuck in this loop, it didn't stall, just stuck there for ever... Now it appears to be working fine.
Thanks for your work @ChuckBell
Hi, I am using an ESP32 so I had to modify the MySQL_Packet_h file to allow use of the MySQL connector, however the serial monitor gets stuck on "Connecting to SQL..". Have any idea as to what would cause this? I'll post the code below.
[code]
include
include
include
IPAddress server_addr(127,0,0,1); // IP of the MySQL server here char user[] = "root"; // MySQL user login username char password[] = ""; // MySQL user login password
// Sample query char INSERT_SQL[] = "INSERT INTO data (sensor,location,value1,value2,value3) VALUES ('Thermocouple', 'office', 20, 20, 20)";
// WiFi card example char ssid[] = ""; // your SSID char 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); } [/code]