ChuckBell / MySQL_Connector_Arduino

Database connector library for using MySQL with your Arduino projects.
332 stars 133 forks source link

Connecting to SQL... FAILED #63

Closed ztb8r3 closed 2 years ago

ztb8r3 commented 6 years ago

I am using the basic insert example on a NodeMCU and I am getting to this point:

Connecting to MySpectrumWiFi28-2G. Connected to network My IP address is: 192.168.1.5 Connecting to SQL... FAILED.

Exception (3): epc1=0x40205a06 epc2=0x00000000 epc3=0x00000000 excvaddr=0x4023820c depc=0x00000000

ctx: cont sp: 3ffefc60 end: 3ffefea0 offset: 01a0

stack>>> 3ffefe00: 2000030a 00000001 3ffe8c55 40205a10
3ffefe10: 4020137a 00000006 3ffe8956 3ffeee78
3ffefe20: 3ffe8904 3ffeea7c 3ffeee4c 40205065
3ffefe30: 4023820c 3ffeea7c 3ffeee4c 3ffeee78
3ffefe40: 3ffe8904 3ffeea7c 3ffeee4c 40205171
3ffefe50: 0501a8c0 3ffeea7c 3fff120c 402031a2
3ffefe60: 3ffe8904 3ffeea7c 3fff120c 40202170
3ffefe70: 40107108 2000030a feefeffe feefeffe
3ffefe80: 3fffdad0 00000000 3ffeee70 40205494
3ffefe90: feefeffe feefeffe 3ffeee80 40100710
<<<stack<<<

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 tail 8 chksum 0x2d csum 0x2d v614f7c32 ~ld

I am trying to connect to a MySQL instance that is hosted by AWS. I have a MySQL workbench open and can connect to my db through it. I have a master user and pass set up. Not sure what this exception is.

Any help appreciated.

ztb8r3 commented 6 years ago

Here is all the code if needed. I don't need to make adjustments to the .h files at all do I?

include // Use this for WiFi instead of Ethernet.h

include

include

IPAddress server_addr(10,3,0,32); // IP of the MySQL server here char user[] = "MYUSER"; // MySQL user login username char password[] = "MYPASS"; // MySQL user login password

// Sample query char INSERT_SQL[] = "INSERT INTO test_arduino.hello_arduino (message) VALUES ('Hello, Arduino!')";

// WiFi card example char ssid[] = "MySpectrumWiFi28-2G"; // your SSID char pass[] = "smartairplane997"; // 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); }

ChuckBell commented 6 years ago

Please ensure the MySQL you're using is an Oracle-released MySQL. The connector may not work with forks of MySQL. Beyond that, ensure your MySQL permissions are setup correctly to allow the remote user to connect.

You also may want to follow the example in the documentation and example sketches to connect, query, then disconnect rather than holding the connection open.

ChuckBell commented 6 years ago

Otherwise, I am not sure what the exception is or why it is being thrown. Sorry. Perhaps if you posted the output in the Serial Monitor and/or try connecting to a local MySQL server to ensure you have a viable script working on a viable board. Remember the golden rule: keep it simple. Minimizing as many things as you can will help you get a working solution faster. ;)

Bolukan commented 6 years ago

I experience the esp8266 needs some time between receiving the ip address and initiating the mysql connnection. (Still digging into the libraries to understand the behaviour) Try moving the connection code to the loop and/or adding some delay in between.

But a simple mistake (non-standard port, etc) is also still possible.

sand007man commented 5 years ago

Here is all the code if needed. I don't need to make adjustments to the .h files at all do I?

include // Use this for WiFi instead of Ethernet.h

include

include

IPAddress server_addr(10,3,0,32); // IP of the MySQL server here char user[] = "MYUSER"; // MySQL user login username char password[] = "MYPASS"; // MySQL user login password

// Sample query char INSERT_SQL[] = "INSERT INTO test_arduino.hello_arduino (message) VALUES ('Hello, Arduino!')";

// WiFi card example char ssid[] = "MySpectrumWiFi28-2G"; // your SSID char pass[] = "smartairplane997"; // 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); }

add a delay of 1 second if (conn.connect(server_addr, 3306, user, password)) delay(1000); else Serial.println("FAILED.");

//In loop MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn); cur_mem->execute(INSERT_SQL); delete cur_mem; conn.close();

Bolukan commented 5 years ago

To check whether it solves your problem, you should insert the delay before the connect (after the wifi) and not after a succesful connection

‘delay(1000); If (conn.connect( etc’

topdancer commented 5 years ago

To see where the code crashes you should use the ESP Exception Decoder, see here https://github.com/me-no-dev/EspExceptionDecoder When you copy the trace information ("stack" etc) into it you will see in which tab/line your code has an issue.