I try connect to MySQL database with Arduino Nano and ENC28j60, but after 3 retry connection failed.
Here is the src:
#include <Ethernet.h>
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(192,168,1,178); // IP of the MySQL *server* here
char user[] = "arduino"; // MySQL user login username
char password[] = "secret"; // MySQL user login password
// Sample query
char INSERT_SQL[] = "insert into mylog.nfc_access (nfcuid, loggerid) values ('a1b2c3d4',1)";
#define MACADDRESS 0x00,0x01,0x02,0x03,0x04,0x05
#define MYIPADDR 192,168,1,188
#define MYIPMASK 255,255,255,0
#define MYDNS 192,168,1,1
#define MYGW 192,168,1,1
#define UARTBAUD 115200
uint8_t mac[6] = {MACADDRESS};
uint8_t myIP[4] = {MYIPADDR};
uint8_t myMASK[4] = {MYIPMASK};
uint8_t myDNS[4] = {MYDNS};
uint8_t myGW[4] = {MYGW};
EthernetClient client;
MySQL_Connection conn((Client *)&client);
void setup() {
Serial.begin(UARTBAUD);
while (!Serial); // wait for serial port to connect
Serial.println(F("Ethernet.begin..."));
Ethernet.begin(mac,myIP,myDNS,myGW,myMASK);
Serial.println(F("Connecting..."));
if (conn.connect(server_addr, 3306, user, password)) {
delay(1000);
}
else {
Serial.println(F("Connection failed."));
while(true);
}
}
void loop() {
}
And here is the output in serial monitor:
Ethernet.begin...
Connecting...
...trying...
...got: 0 retrying...
...trying...
...got: 0 retrying...
...trying...
...got: 0 retrying...
Connection failed.
I checked the server, it's accessible the database by 'arduino' user from the network.
I tried to disable SSL on server but nothing happened.
I created user with this sql command:
CREATE USER 'arduino'@'%' IDENTIFIED WITH mysql_native_password BY 'secret';
GRANT ALL ON mylog TO 'arduino'@'%';
What can I do?