ChuckBell / MySQL_Connector_Arduino

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

WiFi can't connect #134

Closed mSarheed closed 2 years ago

mSarheed commented 4 years ago

Hi. First time using this. I'm using Wemos D1 Mini, and use the example connect_wifi. When I upload the code the Arduino IDE returns with this:

`Executable segment sizes: IROM : 240992 - code in flash (default or ICACHE_FLASH_ATTR) IRAM : 27336 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...) DATA : 1292 ) - initialized variables (global, static) in RAM/HEAP RODATA : 928 ) / 81920 - constants (global, static) in RAM/HEAP BSS : 25248 ) - zeroed variables (global, static) in RAM/HEAP Sketch uses 270548 bytes (28%) of program storage space. Maximum is 958448 bytes. Global variables use 27468 bytes (33%) of dynamic memory, leaving 54452 bytes for local variables. Maximum is 81920 bytes. esptool.py v2.8 Serial port /dev/cu.usbserial-14310 Connecting.... Chip is ESP8266EX Features: WiFi Crystal is 26MHz MAC: b4:e6:2d:29:20:20 Uploading stub... Running stub... Stub running... Changing baud rate to 460800 Changed. Configuring flash size... Auto-detected Flash size: 4MB Flash params set to 0x0340 Compressed 274704 bytes to 199977...

Writing at 0x00000000... (7 %) Writing at 0x00004000... (15 %) Writing at 0x00008000... (23 %) Writing at 0x0000c000... (30 %) Writing at 0x00010000... (38 %) Writing at 0x00014000... (46 %) Writing at 0x00018000... (53 %) Writing at 0x0001c000... (61 %) Writing at 0x00020000... (69 %) Writing at 0x00024000... (76 %) Writing at 0x00028000... (84 %) Writing at 0x0002c000... (92 %) Writing at 0x00030000... (100 %) Wrote 274704 bytes (199977 compressed) at 0x00000000 in 5.0 seconds (effective 435.8 kbit/s)... Hash of data verified.

Leaving... Hard resetting via RTS pin... `

After upload I open the serial monitor with 115200 baud. And the serial monitor shows this: 12:17:19.318 -> wdt reset 12:17:19.318 -> load 0x4010f000, len 1392, room 16 12:17:19.318 -> tail 0 12:17:19.318 -> chksum 0xd0 12:17:19.318 -> csum 0xd0 12:17:19.318 -> v3d128e5c 12:17:19.318 -> ~ld

My entire code is: `/* MySQL Connector/Arduino Example : connect by wifi

This example demonstrates how to connect to a MySQL server from an Arduino using an Arduino-compatible Wifi shield. Note that "compatible" means it must conform to the Ethernet class library or be a derivative with the same classes and methods.

For more information and documentation, visit the wiki: https://github.com/ChuckBell/MySQL_Connector_Arduino/wiki.

INSTRUCTIONS FOR USE

1) Change the address of the server to the IP address of the MySQL server 2) Change the user and password to a valid MySQL user and password 3) Change the SSID and pass to match your WiFi network 4) Connect a USB cable to your Arduino 5) Select the correct board and port 6) Compile and upload the sketch to your Arduino 7) Once uploaded, open Serial Monitor (use 115200 speed) and observe

If you do not see messages indicating you have a connection, refer to the manual for troubleshooting tips. The most common issues are the server is not accessible from the network or the user name and password is incorrect.

Note: The MAC address can be anything so long as it is unique on your network.

Created by: Dr. Charles A. Bell */

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

include

include

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server_addr(10,0,1,35); // IP of the MySQL server here char user[] = "root"; // MySQL user login username char password[] = "secret"; // MySQL user login password

// WiFi card example char ssid[] = "horse_pen"; // your SSID char pass[] = "noname"; // 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

// Begin WiFi section int status = WiFi.begin(ssid, pass); if ( status != WL_CONNECTED) { Serial.println("Couldn't get a wifi connection"); while(true); } // print out info about the connection: else { Serial.println("Connected to network"); IPAddress ip = WiFi.localIP(); Serial.print("My IP address is: "); Serial.println(ip); } // End WiFi section

Serial.println("Connecting..."); if (conn.connect(server_addr, 3306, user, password)) { delay(1000); } else Serial.println("Connection failed."); conn.close();

void loop() { }`

What am I doing wrong?

ChuckBell commented 4 years ago

I do not know why you are not getting satisfaction here. My suggestion is to check the WiFi library. I suspect you need a different library for the Wemos. If that is the case, you will have to change not only your sketch but also the connector. See the Wiki for more details.

Someone from the Wemos world out there have any ideas?

On Apr 28, 2020, at 6:18 AM, Mortadasarheed notifications@github.com wrote:

Hi. First time using this. I'm using Wemos D1 Mini, and use the example connect_wifi. When I upload the code the Arduino IDE returns with this:

`Executable segment sizes: IROM : 240992 - code in flash (default or ICACHE_FLASH_ATTR) IRAM : 27336 / 32768 - code in IRAM (ICACHE_RAM_ATTR, ISRs...) DATA : 1292 ) - initialized variables (global, static) in RAM/HEAP RODATA : 928 ) / 81920 - constants (global, static) in RAM/HEAP BSS : 25248 ) - zeroed variables (global, static) in RAM/HEAP Sketch uses 270548 bytes (28%) of program storage space. Maximum is 958448 bytes. Global variables use 27468 bytes (33%) of dynamic memory, leaving 54452 bytes for local variables. Maximum is 81920 bytes. esptool.py v2.8 Serial port /dev/cu.usbserial-14310 Connecting.... Chip is ESP8266EX Features: WiFi Crystal is 26MHz MAC: b4:e6:2d:29:20:20 Uploading stub... Running stub... Stub running... Changing baud rate to 460800 Changed. Configuring flash size... Auto-detected Flash size: 4MB Flash params set to 0x0340 Compressed 274704 bytes to 199977...

Writing at 0x00000000... (7 %) Writing at 0x00004000... (15 %) Writing at 0x00008000... (23 %) Writing at 0x0000c000... (30 %) Writing at 0x00010000... (38 %) Writing at 0x00014000... (46 %) Writing at 0x00018000... (53 %) Writing at 0x0001c000... (61 %) Writing at 0x00020000... (69 %) Writing at 0x00024000... (76 %) Writing at 0x00028000... (84 %) Writing at 0x0002c000... (92 %) Writing at 0x00030000... (100 %) Wrote 274704 bytes (199977 compressed) at 0x00000000 in 5.0 seconds (effective 435.8 kbit/s)... Hash of data verified.

Leaving... Hard resetting via RTS pin... `

After upload I open the serial monitor with 115200 baud. And the serial monitor shows this: 12:17:19.318 -> wdt reset 12:17:19.318 -> load 0x4010f000, len 1392, room 16 12:17:19.318 -> tail 0 12:17:19.318 -> chksum 0xd0 12:17:19.318 -> csum 0xd0 12:17:19.318 -> v3d128e5c 12:17:19.318 -> ~ld

My entire code is: `/* MySQL Connector/Arduino Example : connect by wifi

This example demonstrates how to connect to a MySQL server from an Arduino using an Arduino-compatible Wifi shield. Note that "compatible" means it must conform to the Ethernet class library or be a derivative with the same classes and methods.

For more information and documentation, visit the wiki: https://github.com/ChuckBell/MySQL_Connector_Arduino/wiki https://github.com/ChuckBell/MySQL_Connector_Arduino/wiki.

INSTRUCTIONS FOR USE

Change the address of the server to the IP address of the MySQL server Change the user and password to a valid MySQL user and password Change the SSID and pass to match your WiFi network Connect a USB cable to your Arduino Select the correct board and port Compile and upload the sketch to your Arduino Once uploaded, open Serial Monitor (use 115200 speed) and observe If you do not see messages indicating you have a connection, refer to the manual for troubleshooting tips. The most common issues are the server is not accessible from the network or the user name and password is incorrect.

Note: The MAC address can be anything so long as it is unique on your network.

Created by: Dr. Charles A. Bell */

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

include

include

byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

IPAddress server_addr(10,0,1,35); // IP of the MySQL server here char user[] = "root"; // MySQL user login username char password[] = "secret"; // MySQL user login password

// WiFi card example char ssid[] = "horse_pen"; // your SSID char pass[] = "noname"; // 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

// Begin WiFi section int status = WiFi.begin(ssid, pass); if ( status != WL_CONNECTED) { Serial.println("Couldn't get a wifi connection"); while(true); } // print out info about the connection: else { Serial.println("Connected to network"); IPAddress ip = WiFi.localIP(); Serial.print("My IP address is: "); Serial.println(ip); } // End WiFi section

Serial.println("Connecting..."); if (conn.connect(server_addr, 3306, user, password)) { delay(1000); } else Serial.println("Connection failed."); conn.close();

void loop() { }`

What am I doing wrong?

— 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/134, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6SHYBUAZVAAJLC7JWSUN3RO2UOXANCNFSM4MSWIEPA.

Ben-GER commented 4 years ago

Hello, I had the same mistake.

12:17:19.318 -> wdt reset 12:17:19.318 -> load 0x4010f000, len 1392, room 16 12:17:19.318 -> tail 0 12:17:19.318 -> chksum 0xd0 12:17:19.318 -> csum 0xd0 12:17:19.318 -> v3d128e5c 12:17:19.318 -> ~ld

And now I tried another WiFi.h and it works. My source code contains a DS18B20 sensor and a DHT22 sensor. Both enter their values ​​into the MySQL database at regular intervals via the WiFi interface.

` /* MySQL Connector/Arduino Example : connect by wifi

This example demonstrates how to connect to a MySQL server from an Arduino using an Arduino-compatible Wifi shield. Note that "compatible" means it must conform to the Ethernet class library or be a derivative with the same classes and methods.

For more information and documentation, visit the wiki: https://github.com/ChuckBell/MySQL_Connector_Arduino/wiki.

INSTRUCTIONS FOR USE

1) Change the address of the server to the IP address of the MySQL server 2) Change the user and password to a valid MySQL user and password 3) Change the SSID and pass to match your WiFi network 4) Connect a USB cable to your Arduino 5) Select the correct board and port 6) Compile and upload the sketch to your Arduino 7) Once uploaded, open Serial Monitor (use 115200 speed) and observe

If you do not see messages indicating you have a connection, refer to the manual for troubleshooting tips. The most common issues are the server is not accessible from the network or the user name and password is incorrect.

Note: The MAC address can be anything so long as it is unique on your network.

Created by: Dr. Charles A. Bell */

include

include

include

include

include "DHT.h"

ifndef STASSID

define STASSID "YOUR_ROUTER"

define STAPSK "YOUR_PASSWORD"

endif

IPAddress server_addr(192, 168, 178, 1); // IP of the MySQL server here char user[] = "USER"; // MySQL user login username char password[] = "YOUR_PASSWORD_SQL!!!"; // MySQL user login password

// WiFi card example const char ssid = STASSID; const char pass = STAPSK;

char INSERT_AUSSEN[] = "INSERT INTO Sensoren.aussen_temp_tb (zeit, wert) VALUES (UNIX_TIMESTAMP(), %s)"; char INSERT_WOHN_TEMP[] = "INSERT INTO Sensoren.wohn_temp_tb (zeit, wert) VALUES (UNIX_TIMESTAMP(), %s)"; char INSERT_WOHN_FEUCHT[] = "INSERT INTO Sensoren.wohn_feucht_tb (zeit, wert) VALUES (UNIX_TIMESTAMP(), %s)"; char query[128]; char aussen_temp[10]; char wohn_temp[10]; char wohn_feucht[10];

WiFiClient client; // Use this for WiFi instead of EthernetClient MySQL_Connection conn((Client *)&client); DS18B20 ds(4); // Nutzung von GPIO4 DHT dht(5, DHT22); // Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --

void setup() { Serial.begin(115200);

// WiFi Aufbau Sektion Serial.println(); Serial.print("Verbinde zu Router "); Serial.println(ssid);

WiFi.mode(WIFI_STA); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print(". "); } Serial.println(""); Serial.println("WiFi verbunden"); Serial.println("IP Addresse: "); Serial.println(WiFi.localIP()); // WiFi Ende Aufbau

Serial.println("Verbindet..."); if (conn.connect(server_addr, 3306, user, password)) { delay(3000); Serial.println("Verbindung hergestellt"); delay(1000); } else Serial.println("Verbindung fehlgeschlagen."); conn.close();

dht.begin(); }

void loop() { // DS18B20 Daten einlesen und in MySQL schreiben uint8_t address[8]; ds.getAddress(address);

Serial.print("Temperatur: "); Serial.print(ds.getTempC()); Serial.println(" C"); delay(1000); if (conn.connect(server_addr, 3306, user, password)) { MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn); dtostrf(ds.getTempC(), 1, 1, aussen_temp); sprintf(query, INSERT_AUSSEN, aussen_temp); cur_mem->execute(query); delete cur_mem; Serial.println("Daten gespeichert."); } else Serial.println("Verbindung fehlgeschlagen."); conn.close(); delay(59000);

// DHT22 Daten einlesen und in MySQL schreiben delay(2000); float feucht = dht.readHumidity(); float temp = dht.readTemperature(); if (isnan(feucht) || isnan(temp)) { Serial.println(F("DHT Sensordaten koennen nicht gelesen werden!")); return; } float gefuehlt = dht.computeHeatIndex(temp, feucht, false);

Serial.print(F("Humidity: ")); Serial.print(feucht); Serial.print(F("% Temperature: ")); Serial.print(temp); Serial.print(F("°C ")); Serial.print(F(" Heat index: ")); Serial.print(gefuehlt); Serial.println(F("°C ")); delay(1000); if (conn.connect(server_addr, 3306, user, password)) { MySQL_Cursor cur_mem = new MySQL_Cursor(&conn); dtostrf(temp, 1, 1, wohn_temp); sprintf(query, INSERT_WOHN_TEMP, wohn_temp); cur_mem->execute(query); delete cur_mem; Serial.println("Daten gespeichert."); } else Serial.println("Verbindung fehlgeschlagen."); conn.close(); delay(2000); if (conn.connect(server_addr, 3306, user, password)) { MySQL_Cursor cur_mem = new MySQL_Cursor(&conn); dtostrf(feucht, 1, 1, wohn_feucht); sprintf(query, INSERT_WOHN_FEUCHT, wohn_feucht); cur_mem->execute(query); delete cur_mem; Serial.println("Daten gespeichert."); } else Serial.println("Verbindung fehlgeschlagen."); conn.close(); delay(55000); } `

Thank you for the MySQL library Dr. Charles A. Bell.

Info: The thickly marked places must be adjusted on your own.

Regards Ben

ChuckBell commented 2 years ago

Closed due to inactivity. Please open a new ticket if this is still relevant.