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.

share|improve this question
    
Can the gateway machine communicate with the server? – Ignacio Vazquez-Abrams Dec 7 '14 at 11:21
    
Yes, it can. I can also ping it from this computer which is also in the 192.168.10.x net. – user3433131 Dec 7 '14 at 11:22
    
Can you ping from the Uno to the server? aka from 192.168.10.127 to 192.168.2.100? Are you sure that port 3306 is not being blocked by the gateway (aka not ping, but login using 'this' computer or similar at 192.168.10.x)? – Omer Dec 7 '14 at 14:27
    
Sorry for the delay. Port 3306 is not being blocked. I'll start looking into pinging from the Arduino, but it should be the same because the Arduino and my laptop ('this' computer) are in the 192.168.10.x net. – user3433131 Dec 7 '14 at 20:00
1  
Update: I most certainly can ping the server from the Arduino. I'll start looking at Windows MySQL clients to try it out. – user3433131 Dec 7 '14 at 20:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.