Hello,
arduino 2009 with official eth shield and IDE 1.0 here
Someday ago, zoomkat saves my day with an example to mix web server and web client.
Now I have implemented a dns with openDNS... but the thing goes strange.
First point.
If there is a internet connection, everything works fine.
My address is actually resolved and the connection (sending data to pachube) works.
But there are some strange behaviors when there is NOT an internet connection.
In particular:
if (client.connect(myserver, 80)) {
always returns... true. Even if there is no internet connection.
Even if I unplug the eth cable from the Ethernet shield.
How's that? Any suggestion?
When there is no internet connection the packets sniffing with whireshark returns a dns query and an ICMP host unreachable.
But I don't know why the if always return true.
If I use IPAddress myserver instead of name, removing dns code, the if works fine.
Any help will be appreciated.
It's the last piece of my project, I can live without that but... I prefer having everything tuned fine!
This is my code:
/************ ETHERNET STUFF ************/
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,0,9); // IP in lan
IPAddress gateway(192,168,0,1); // Internet access via router
IPAddress subnet(255,255,255,0); // Subnet mask
IPAddress dns(208,67,222,222); // OpenDNS IP
EthernetServer server(84); // Porta webserver
/*--------- Pachube ---------*/
// IPAddress myserver(216,52,233,122); // The address of the server you want to connect to (pachube.com)
char myserver[] = "pachube.com";
EthernetClient client; // initialize the library instance
setup:
Ethernet.begin(mac,ip,dns,gateway,subnet);
server.begin();
loop.
Here's come the strangeness.
if (client.connect(myserver, 80)) {
pachubestatus=1;
PgmPrintln("Connecting to Pachube...");
// send the HTTP PUT request.
client.print(F("PUT /v2/feeds/xxx.csv HTTP/1.1\n"));
client.print(F("Host: api.pachube.com\n"));
// send the Pachube API key here:
client.print(F("X-PachubeApiKey: xxx\n"));
client.print(F("Content-Length: "));
client.print( lngstring );
client.print(F("\n"));
client.print(F("Connection: close\n"));
client.println();
// here's the actual content of the PUT request:
client.print(F("t_out,"));
client.print(charbuffertout);// t_out
PgmPrintln("Connection Done... Maybe.");
}
else {
// if you couldn't make a connection:
pachubestatus=0;
PgmPrintln("Connection failed!");
}
client.stop();
delay (500);
Thankyou