So I was going to make a project with the MySQL Connector/Arduino; a temperature log. I started out by experimenting with the example code from the website linked above. Not once did I manage to actually connect to the server; the mysql_connect() function always returns false. After several hours of intense googling, innumerable irritated noises and more, I decided to ask here on Stack Exchange.
Here is my current code:
#include "SPI.h"
#include "Ethernet.h"
#include "sha1.h"
#include "mysql.h"
byte mac_addr[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x69, 0xAC };
byte ip_addr[] = { 192, 168, 10, 127 };
byte dns_addr[] = { 192, 168, 10, 1 };
byte gateway_addr[] = { 192, 168, 10, 1 };
byte netmask[] = { 255, 255, 255, 0 };
IPAddress server_addr(192, 168, 2, 100);
Connector my_conn; // The Connector/Arduino reference
char user[] = "";
char password[] = ""; //the credentials are correct in my code
char INSERT_SQL[] = "INSERT INTO test_arduino.hello VALUES ('Hello, MySQL!');";
void setup() {
Serial.begin(115200);
Ethernet.begin(mac_addr, ip_addr, dns_addr, gateway_addr, netmask); //Yes, I know this is way more than necessary, but just to play it safe
delay(1000);
Serial.print("IP: ");
Serial.println(Ethernet.localIP()); // debugging
Serial.println("Connecting...");
if (my_conn.mysql_connect(server_addr, 3306, user, password)) //connect to database
{
delay(500);
my_conn.cmd_query(INSERT_SQL);
Serial.println("Query Success!");
}
else
Serial.println("Connection failed.");
}
void loop() {
}
Any help is greatly appreciated.
Rasmus
EDIT: Looks like I'm not even getting through to reaching the server and attempting to log in. I enabled the general query logs, yet I get nothing when trying to connect. Also, I can ping both the Arduino and the MySQL server from this computer. I guess that rules out a faulty shield and network setup.