-1

I have problem to store values to MySQL table from Arduino MKR 1010 Wifi. I get the following message.

trying
got: 0 retrying
trying
got: 0 retrying
ERROR!

I have also tried to turn off firewall without success. Is my code wrong? Can someone help me with this issue?

#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include <MySQL_Encrypt_Sha1.h>
#include <MySQL_Packet.h>
#include <DHT.h>
#include <DHT_U.h>
#include <dht.h>
#include <WiFiNINA.h>
#include <wifiinfo.h>

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

#define DHT22_PIN 7
#define DHTTYPE 22 DHT deviceMonitor(DHT22_PIN,DHTTYPE) ;

IPAddress server_addr(192,168,86,39); // IP of the MySQL server here char user[] = "root"; // MySQL user login username char password2[] = "test1234"; // MySQL user login password

char ssid[] = SECRET_SSID; // your network SSID (name) char password[] = SECRET_PASS; // your network password (use for WPA, or use as key for WEP) int status = WL_IDLE_STATUS; // the Wifi radio's status

float hum; float temp; float humError; float tempError; int checkTemp;

char INSERT_DATA[] = "INSERT INTO weather (temp, hum) VALUES ('%s','%d')"; char query[128]; char temperature[10];

EthernetClient client; MySQL_Connection conn((Client *)&client);

void setup() { //Initialize serial and wait for port to open: Serial.begin(9600); while (!Serial); // wait for serial port to connect Ethernet.begin(mac_addr);

// attempt to connect to Wifi network: while (status != WL_CONNECTED) { Serial.print("Attempting to connect to network: "); Serial.println(ssid); // Connect to WPA/WPA2 network: status = WiFi.begin(ssid, password);

// wait 10 seconds for connection:
delay(10000);

}

// you're connected now, so print out the data: Serial.println("You're connected to the network");

Serial.println("----------------------------------------"); printData(); Serial.println("----------------------------------------");

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

void loop() { delay(5000); if (conn.connect(server_addr, 3306, user, password2)) {

MySQL_Cursor *cur_mem = new MySQL_Cursor(&amp;conn);
checkTemp = deviceMonitor.read(DHT22_PIN);
hum = deviceMonitor.readHumidity();
temp = deviceMonitor.readTemperature();
Serial.println((String)&quot;Temperature: &quot; + temp + &quot; Celsius&quot;);
Serial.println((String)&quot;Humidity: &quot; + hum +&quot;%&quot;);
Serial.println();
sprintf(query, INSERT_DATA, temp, hum);
cur_mem-&gt;execute(query);
delete cur_mem;
Serial.println(&quot;Data recorded.&quot;);
delay(10000);

} else { Serial.println("ERROR!"); } }

void printData() { Serial.println("Board Information:"); // print your board's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip);

Serial.println(); Serial.println("Network Information:"); Serial.print("SSID: "); Serial.println(WiFi.SSID());

// print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.println(rssi);

byte encryption = WiFi.encryptionType(); Serial.print("Encryption Type:"); Serial.println(encryption, HEX); Serial.println(); }

Ken76
  • 1
  • 1

1 Answers1

0

I granted full right to user root in MySQL and now got this error instead.

ERROR: Timeout waiting for client.
Error: -1 = Mysql connection failed.

Can someone help me with this problem?

Ken76
  • 1
  • 1