Ciao a tutti!
stavo cercando ci creare un sistema con un server web dove Arduino con la sua Ethernet Shield invia i dati mediante comando GET. Sul server gira un semplice script php che ascolta le GET che arrivano e salva il valore in un file di testo.
Lo sketch l'ho ottenuto facendo poche modifiche all'esempio WebClient presente nel'IDE 1.0
eccolo...
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(192,168,xxx,xxx); // mio server
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;
void setup() {
// start the serial library:
Serial.begin(9600);
// start the Ethernet connection:
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
for(;;)
;
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 8080)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /ricezionedati.php?miotesto=testo_inviato HTTP/1.0");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;;)
;
}
}
e questo è il php che gira sul webserver che ho installato sul mio pc
<?php
$a=$_GET["miotesto"];
if (strlen($_GET["miotesto"])){
$write_file = fopen("file.txt","w");
fwrite($write_file,$a);
fclose($write_file);
}
?>
Il tutto funziona benissimo!!! ma io vorrei poter inviare le GET con Arduino allo stesso script PHP che ho messo sul mio account che mi sono creato su Altervista.org!
Come faccio a far collegare Arduino a "miosito.altervista.org" anziché a 192.168.xxx.xxx (che è il server che gira sul mio pc)???
Grazie in anticipo e W ARDUINO!!!