I'm using an Arduno UNO WiFi Rev 2 and trying to connect to a database, but it does not connect nor shows any errors.
The arduino connects successfully to WiFi and pinging google works fine. But when I add the part to connect to database, on line: 65, the script just stops at "DB Connecting..." on the line above.
Inside Arduino IDE you can see a difference between the includes, the MySQL ones are not luminated: https://i.imgur.com/is0bK5B.png
This is how the code looks like:
#include <SPI.h>
#include <WiFiNINA.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
// MySQL Information
IPAddress server_addr(111,222,333,4);
char user[] = "arduino"; // MySql username
char password[] = "qwerty"; // MySql password
WiFiClient client;
MySQL_Connection conn((Client *)&client);
// WiFi Information
char ssid[] = "Router-SSID"; // your network SSID (name)
char pass[] = "router-pw"; // your network password (use for WPA, or use as key for WEP)
int status = WL_IDLE_STATUS; // the WiFi radio's status
// Specify IP address or hostname
String hostName = "www.google.com";
int pingResult;
int pingWorks = 0;
void setup() {
pinMode(hallPin, INPUT);
pinMode(LED, OUTPUT);
Serial.begin(115200);
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE) {
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true);
}
String fv = WiFi.firmwareVersion();
if (fv < "1.0.0") {
Serial.println("Please upgrade the firmware");
}
// attempt to connect to WiFi network:
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network:
status = WiFi.begin(ssid, pass);
// wait 5 seconds for connection:
delay(5000);
}
// you're connected now, so print out the data:
Serial.println("You're connected to the network");
printCurrentNet();
printWiFiData();
delay(2000);
Serial.println(server_addr);
Serial.println(user);
Serial.println(password);
// Connected to the WiFi lets continue..
Serial.println("DB - Connecting...");
if (conn.connect(server_addr, 3306, user, password)) {
delay(500);
Serial.print ( "." );
} else {
Serial.println("Failed to connect..");
}
Serial.println("Connected.");
}
void loop() {
runWifi();
}
void runWifi() {
if (pingWorks == 0) {
Serial.print("Pinging ");
Serial.print(hostName);
Serial.print(": ");
pingResult = WiFi.ping(hostName);
if (pingResult >= 0) {
Serial.print("SUCCESS! RTT = ");
Serial.print(pingResult);
Serial.println(" ms");
pingWorks = 1;
} else {
Serial.print("FAILED! Error code: ");
Serial.println(pingResult);
pingWorks = 2;
}
} else {
Serial.println("Ping on google works..");
}
delay(200);
}
void printWiFiData() {
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP address : ");
Serial.println(ip);
Serial.print("Subnet mask: ");
Serial.println((IPAddress)WiFi.subnetMask());
Serial.print("Gateway IP : ");
Serial.println((IPAddress)WiFi.gatewayIP());
// print your MAC address:
byte mac[6];
WiFi.macAddress(mac);
Serial.print("MAC address: ");
printMacAddress(mac);
}
void printCurrentNet() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print the MAC address of the router you're attached to:
byte bssid[6];
WiFi.BSSID(bssid);
Serial.print("BSSID: ");
printMacAddress(bssid);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI): ");
Serial.println(rssi);
// print the encryption type:
byte encryption = WiFi.encryptionType();
Serial.print("Encryption Type: ");
Serial.println(encryption, HEX);
Serial.println();
}
void printMacAddress(byte mac[]) {
for (int i = 5; i >= 0; i--) {
if (mac[i] < 16) {
Serial.print("0");
}
Serial.print(mac[i], HEX);
if (i > 0) {
Serial.print(":");
}
}
Serial.println();
}
What can be the problem? No working libs for WiFi uno rev 2?