Arduino based SQL Queries

Share on facebook
Share on google
Share on twitter
Share on linkedin
A VPN is an essential component of IT security, whether you’re just starting a business or are already up and running. Most business interactions and transactions happen online and VPN

We are successfully performing SQL queries on two Arduino’s, one in the US, one in Italy, inserting data into a HostGator hosted MySQL server. We are polishing a spiffy PHP / Ajax interface so you can see the results.

INSERT – Done!
SELECT – Done!
UPDATE – Done!
DELETE – Done!

Got all 4 queries working. DELETE, UPDATE, SELECT, and INSERT. Ran out of memory on the UNO, had to step up to a 2560.

Here’s a taste of what’s going on:

void read_data() {

sensorValue = analogRead(sensorPin);
char buf[128];
sprintf(buf, “INSERT INTO spspence_test_arduino.temp VALUES (%i)”,
sensorValue);
my_conn.cmd_query(buf);
Serial.println(“Data read and recorded.”);
Serial.println(sensorValue);

}

void setup() {
Ethernet.begin(mac);
Serial.begin(9600);
delay(1000);
Serial.println(“Connecting…”);
if (my_conn.mysql_connect(server_addr, 3306, user, password))
delay(500);
else
Serial.println(“Connection failed.”);
}

void loop() {
delay(read_delay);
read_data();
}

Learn more by reading Beginning Sensor Networks with Arduino & Raspberry Pi by Charles Bell

 

Steve Spence

Steve Spence

Leave a Reply

Leave a Comment

Your email address will not be published. Required fields are marked *