Tuesday, April 15, 2014

Arduino based SQL Queries

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 (example). 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


Sunday, April 13, 2014

Arduino Internet Time Client

UPDATE!
Added 12h/24h switch and Standard / Daylight Savings Time Switch! See steps 7 & 8.


Typically computers get their internal clocks adjusted by connecting to a Network Time Server (Internet or Local), using the Network Time Protocol (NTP). That functionality is also available to microcontrollers like the Arduino. We have put together an inexpensive and easy to follow instructable that will allow you to add official time keeping to a project. Have fun!

http://www.instructables.com/id/Arduino-Internet-Time-Client/