Hello,
I have Arduino Uno Wifi Rev2.
I succesfully connected to my wifi.
Now I'm trying to connect it to mysql server.
I have Raspberry Pi and I have installed apache, mysql and phpmyadmin and they work correctfully.
Here is my code:
#include <WiFiNINA.h> // Use this for WiFi instead of Ethernet.h
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
char ssid[] = SECRET_SSID; // your network SSID (name)
int status = WL_IDLE_STATUS; // the Wifi radio's status
//byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(192,168,43,219); // IP of the MySQL *server* here
char user[] = "root"; // MySQL user login username
char password[] = "testing123"; // MySQL user login password
WiFiClient client; // Use this for WiFi instead of EthernetClient
MySQL_Connection conn((Client *)&client);
void setup() {
Serial.begin(115200);
// Begin WiFi section
int status = WiFi.begin(ssid);
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)) {
Serial.println("Connected");
delay(1000);
}
else
Serial.println("Connection failed.");
conn.close();
}
void loop() {
delay(2000);
Serial.println("Connected");
}
and in arduino_secrets it's: #define SECRET_SSID "ASUSWeb" (my wifi)
How can I check, does this really connect to my mysql and how can I make it to write some content in some database? I create database called "test".
Thank you for your replies!