Salve. Sto realizzando un controllo da remoto con Arduino Uno e scheda Wiznet W500 e sono riuscito a gestire senza problemi lo Shield in rete locale, sia con l'esempio "WebServer" e sia con uno sketch che ho trovato in rete per comandare dei led.
Ora sto provando a comandare lo Shield da una rete esterna (quella dello smartphone): per questo ho creato un host su no-ip.com e ne ho inserito i dati all'interno di questo sketch:
/*
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
modified for no-ip client example
by Jerry Sy aka doughboy
*/
#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 };
// 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("dynupdate.no-ip.com", 80)) {
Serial.println("connected");
// Make a HTTP request:
//replace yourhost.no-ip.org with your no-ip hostname
client.println("GET /nic/update?hostname=ilmiohost.no-ip.biz HTTP/1.0");
client.println("Host: dynupdate.no-ip.com");
//encode your username:password (make sure colon is between username and password)
//to base64 at http://www.opinionatedgeek.com/dotnet/tools/base64encode/
//and replace the string below after Basic with your encoded string
//clear text username:password is not accepted
client.println("Authorization: Basic *****************");
client.println("User-Agent: ilmionhost Client/0.0 lamiamail");
client.println();
}
else {
// if 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 questa è la mia risposta sul serial monitor:
https://drive.google.com/file/d/0B4bjpRHcU_eSRkM3NFJPbHBoWm8/edit?usp=sharing
Quello che ho capito è di essere riuscito ad accedere con l'Arduino al mio host, almeno credo. Il problema sta nel fatto che quando accedo al mio host (dallo smartphone o da PC) all'indirizzo http://www.noip.com/nic/update?hostname=ilmiohost.no-ip.biz mi appare sempre e comunque la scritta "nochg" (oppure la scritta "good" seguita dall'indirizzo IP), indipendentemente da ciò che scrivo nel void loop. Come faccio quindi a far apparire, ad esempio, la pagina dello sketch "WebServer" nel mio host? Perché ho provato ad unire lo sketch che ho riportato sopra con "WebServer" ma nulla da fare. Grazie.