Buongiorno ragazzi, io e il mio collega stiamo impazzendo, per far scrivere nel database i dati della temperatura rilevati da arduino, con sopra la ethernet shield e la thinkerkit con il sensore temperatura attaccato, senza utilizzare php, dato che vogliamo scrivere sul database.
Cercando su google abbiamo trovato un esempio fatto da Charles Andrew Bell ma c'è una stringa di codice che sembra bloccare tutto (if (my_conn.mysql_connect(server_addr, 3306, user, password))), il codice è questo:
#include <SPI.h>
#include <Ethernet.h>
#include <sha1.h>
#include <avr/pgmspace.h>
#include <mysql.h>
#include <TinkerKit.h>
TKThermistor therm(I5); // creating the object 'therm' that belongs to the 'TKThermistor' class
TKLed led(9) ; // and giving the value to the desired output pin
float C, F; // temperature readings are returned in float format
byte mac_addr[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x1F, 0x41 };
IPAddress ip_addr(192, 168, 0, 44);
IPAddress server_addr(192, 168, 0, 171);
char user[] = "root";
char password[] = "";
char buf[128];
Connector my_conn;
void setup()
{
// initialize serial communications at 9600 bps
Ethernet.begin(mac_addr);
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()
{
C = therm.getCelsius(); // Reading the temperature in Celsius degrees and store in the C variable
F = therm.getFahrenheit(); // Reading the temperature in Fahrenheit degrees and store in the F variable
// Print the collected data in a row on the Serial Monitor
Serial.print("Analog reading: \t"); // Reading the analog value from the thermistor
Serial.print(therm.getCelsius());
Serial.print("\tC: \t");
Serial.print(C);
sprintf(buf, "INSERT INTO test.temp VALUES (NULL, %hi.%01hi, %i.%01i)",
C,
C,
C,
C);
my_conn.cmd_query(buf);
Serial.print("Data read and recorded.");
}
Se avete delle idee per aiutarmi ne sarei molto felice