Ho trovato questo codice sulla pagina linkata da ST_e:
potremmo implementarlo
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 88 };
byte gw[] = {192,168,1,1};
byte server[] = { xxx, xxx, xxx, xxx }; // Server IP
byte subnet[] = { 255, 255, 255, 0 };
int data = 0;
int tempPin = 2; // In This case the temperature is taken from pin 2 and sent to a sql server
void setup()
{
pinMode(tempPin, INPUT);
Serial.begin(9600); // Used for serial debugging
}
void loop()
{
Serial.println("Program running...");
delay(5000);
senddata(); // Data is sent every 5 seconds
}
void senddata()
{
data = analogRead(tempPin); //Reading analog data
Ethernet.begin(mac, ip, gw, subnet);
Client client(server, 80);
Serial.println();
Serial.println("Forbinder?");
delay(1000); //Keeps the connection from freezing
if (client.connect()) {
Serial.println("Connected");
client.print("GET http://server.com/script.php?vaerdi=");
client.print(data);
client.println(" HTTP/1.1");
client.println("Host: www.server.com");
client.println();
Serial.println();
}
else
{
Serial.println("Connection unsuccesfull");
}
//}
//stop client
client.stop();
while(client.status() != 0)
{
delay(5);
}
}
CODICE PHP (che starà sul server.)
<html>
<?php
$DATA = $_GET['vaerdi'];
//Connect to database
$opendb = mysql_connect("xxx.xxx.xxx.xxx", "database", "password") or mysql_error("Could not connect to database");
mysql_select_db("database");
if ($opendb)
{
mysql_query(" INSERT INTO tabel (Dato, DATA) VALUES ( NOW() , $DATA )");
mysql_close($opendb);
}
?>
</html>