devi usare un server DNS che trasmorma l'indirizzo HTTP (miosito.altervista.org) in indirizzo IP. dovresti trovare delle librerie già fatte.
purtroppo non è sufficiente, anche qui se ne era parlato:
Il fatto è che su web gran parte degli host (gratuiti o meno che siano), utilizzano Virtual Server.
Questo significa che non c'è rapporto 1:1 tra indirizzo web e indirizzo ip.
Lato server infatti, in base al fqdn name presente nella chiamata (es xxxx.altervista.org), la richiesta viene indirizzata verso un server virtuale o un'altro.
La prova del 9:
$ nslookup xxxxxx.altervista.org
...
Non-authoritative answer:
Name: xxxxxx.altervista.org
Address: 78.46.92.147
Quindi l'indirizzo ip di xxxxxx.altervista.org è 78.46.92.147
Se su web browser inserisco quell'ip, mi si aprirà però la pagina di altervista (http://it.altervista.org/)
Questo è un esempio con Altervista, perchè qui se ne parla e anche nel thread aperto da ratto93.
La stessa cosa però vale per la maggior parte di web hosting (gratuiti o meno che sia) - discorso diverso se si ha un server dedicato, ma dubito che qui ce l'abbiano i molti...
Dopo il thread i ratto93, mi son messo a ragionare sulla cosa, e mi son reso conto di avere la risposta sotto il naso.
La chiamata GET accetta come parametro nell'header anche Host, in specifico:
The "Host" header distinguishes between various DNS names sharing a single IP address, allowing name-based virtual hosting.
Quindi, rivedendo il nostro codice, come indirizzo del server andrà messo l'ip di altervista (esempio calato a pennello per il ns. caso), e nella richiesta basterà aggiungere nell'header il parametro Host, con il nostro fqdn (xxxxx.altervista.org)
Esempi pratico, adattato dall'esempio WebClient dell'IDE, con riferimenti al threadi di ratto93:
/*
Web client
This sketch connects to a website (http://www.google.com)
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 18 Dec 2009
by David A. Mellis
*/
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10,0,10,5 };
byte subnet[] = { 255,255,0,0 };
byte gateway[] = { 10,0,3,79 };
byte server[] = { 176, 9, 63, 22}; //altervista ip, risultato del ping ratto93.altervista.org
// 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):
Client client(server, 80);
void setup() {
// start the Ethernet connection:
Ethernet.begin(mac,ip,gateway,subnet);
// start the serial library:
Serial.begin(115200);
// 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()) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET /index.php?temperatura=22&umidita=22 HTTP/1.0"); //GET da effettuare
client.println("Host: ratto93.altervista.org"); //parametro Host per gestione virtual server
client.println(); //riga vuota
}
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(;;)
;
}
}
Questo metodo permette di utilizzare Arduino con praticamente tutti i servizi di web hosting su web, basati su Virtual Server (ovvero quasi tutti).