So, im using a Mega 2560 and a Ethernet to send some data to a Mysql database, but the conn.connect(server_addr, 3306, user, password) seems never returns true, so here is my arduino code:
#include <Ethernet.h>
#include <MySQL_Connection.h>
byte mac_addr[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(200,129,38,54); // IP of the MySQL *server* here
char user[] = "root"; // MySQL user login username
char password[] = "root"; // MySQL user login password
EthernetClient client;
MySQL_Connection conn((Client *)&client);
void setup() {
Serial.begin(9600);
while (!Serial); // wait for serial port to connect
Ethernet.begin(mac_addr);
Serial.println("Connecting...");
if (conn.connect(server_addr, 3306, user, password)) {
delay(1000);
Serial.println("Conectado");
// You would add your code here to run a query once on startup.
}
else
Serial.println("Connection failed.");
conn.close();
}
void loop() {
}
The server_addr its correct, this ip i changed on Ethernet Adapter, on the ipv4. The arduino is connected directly with my pc.
The MySQL Workbench is saying that the server is on
It looks like your mac address is identical to the example code. You need to change it to match the real mac address of your ethernet shield. It is usually on a sticker on the shield.
Ok guys, sorry for the late reply, my e-mail seems doesn't be notifying me so, i changed the mac address and i add a ip addres, the code now is :
/*
MySQL Connector/Arduino Example : connect
This example demonstrates how to connect to a MySQL server from an
Arduino using an Arduino-compatible Ethernet shield. Note that "compatible"
means it must conform to the Ethernet class library or be a derivative
thereof. See the documentation located in the /docs folder for more
details.
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) Connect a USB cable to your Arduino
4) Select the correct board and port
5) Compile and upload the sketch to your Arduino
6) 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 <Ethernet.h>
#include <MySQL_Connection.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(200,129,38,114);
IPAddress server_addr(200,129,38,54); // IP of the MySQL *server* here
char user[] = "root"; // MySQL user login username
char password[] = "root"; // MySQL user login password
EthernetClient client;
MySQL_Connection conn((Client *)&client);
void setup() {
Serial.begin(9600);
while (!Serial); // wait for serial port to connect
Ethernet.begin(mac, ip);
Serial.println(Ethernet.localIP());
Serial.println("Connecting...");
if (conn.connect(server_addr, 3306, user, password)) {
delay(1000);
Serial.println("Connection sucesfull");
// You would add your code here to run a query once on startup.
}
else
Serial.println("Connection failed.");
conn.close();
}
void loop() {
}
when i do ping 200,129,38,114 it work and i can see the mac address on the cmd so i think its working, the issue im having now doesnt seems be a big thing, its more a problem from the database, " Error: 77 = Access denied for user 'root'@'200.129.38.114' (using password: YES). " ill search a resolution, thanks guys !!!!