Taken the code below, how do you loop so that the data continues to insert into the database for a specified time?
#include <SPI.h>
#include <Ethernet.h>
#include <sha1.h>
#include <stdlib.h>
#include <mysql.h>
byte mac_addr[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server_addr(192, 168, 2, 13); // Supply the IP of the MySQL *server* here
char user[] = "admin"; // can be anything but the user must have
char password[] = "fmeo"; // access rights to connect (host must permit it)
// WiFi card example
//char ssid[] = "my_lonely_ssid";
//char pass[] = "horse_no_name";
Connector my_conn; // The Connector/Arduino reference
// String constants for examples. Uncomment those you need.
const char INSERT_DATA[] = "INSERT INTO test_arduino.temps VALUES (%s, NULL)";
const char HELLO_DATA[] = "SELECT * from test_arduino.temps";
/**
* do_query - execute a query and display results
*
* This method demonstrates how to execute a query, get the column
* names and print them, then read rows printing the values. It
* is a mirror of the show_results() example in the connector class.
*
* You can use this method as a template for writing methods that
* must iterate over rows from a SELECT and operate on the values read.
*
*/
void setup() {
Serial.begin(115200);
while (!Serial); // wait for serial port to connect. Needed for Leonardo only
Ethernet.begin(mac_addr);
Serial.print("My IP address is: ");
Serial.println(Ethernet.localIP());
// }
delay(1000);
Serial.println("Connecting...");
if (my_conn.mysql_connect(server_addr, 3306, user, password)) {
delay(1000);
}
else
Serial.println("Connection failed.");
// EXAMPLE 5
// Inserting real time data into a table.
// Here we want to insert a row into a table but in this case we are
// simulating reading the data from a sensor or some other component.
// In this case, we 'simulate' reading temperature in celsius.
float value_read = 26.9;
// To use the value in an INSERT statement, we must construct a string
// that has the value inserted in it. For example, what we want is:
// 'INSERT INTO test_arduino.temps VALUES (26.9, NULL)' but the 26.9 is
// held in the variable 'value_read'. So, we use a character string
// formatting operation sprintf(). Notice here we must convert the float
// to a string first and we use the %s specifier in the INSERT_DATA
// string.
char query[64];
char temperature[10];
dtostrf(value_read, 1, 1, temperature);
sprintf(query, INSERT_DATA, temperature);
my_conn.cmd_query(query);
}
void loop() {
}