I have installed the new version of the Ethernet Shield w/ SD Card Reader (Wiz5100) on a Duemilanove with Atmega328. I have no problems uploading the Ethernet.h library demo server sketch and having accessing it on the local network via the IP I assign in the sketch. Works great. Verified it by taking the different pins high and low and whatnot. Yay.
The client is infuriating me. I'm not sure it's an Ethernet Shield problem though - as when I run the sketch trying to connect to a new server that I haven't connected to before, it connects just fine. If I try to connect to that server again, it bombs out. Won't connect again. If I cycle the power to the board 100 times, it might connect once. But, if I enter a new IP for another server, it connects just fine, but only the one time. This is leading me to believe that it might be a router / firewall issue. I'm using a Dlink DGL-4500 router, and I've set the arduino up to have a DHCP reservation of x.x.x.105 and then placed that address in the DMZ. It didn't correct anything, but I'm not positive the DMZ on the router is worth a pile of beans.
Has anyone experienced this behavior before? Here's the code I'm using - it's basically the example sketch, modified for my IP, with gateway and subnet added in per the advice of another thread on here.
/*
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[] = { 0x90, 0xA2, 0xDA, 0x00, 0x85, 0x56 };
byte ip[] = { 192, 168, 2, 105 };
byte gateway[] = { 192, 168, 2, 1 };
byte subnet[] = { 255, 255, 255, 0 };
//byte server[] = { 74,220,204,126 }; // angryamerica
//byte server[] = { 207,58,139,247 }; // adafruit
//byte server[] = { 74, 125, 224, 179 }; // google
byte server[] = { 192, 168, 2, 193 }; // WHS-02
Client client(server, 80);
void setup()
{
Ethernet.begin(mac, ip, gateway, subnet); // start ethernet using the mac and IP address
Serial.begin(9600); // start the serial library:
delay(1000); // give the ethernet hardware a second to initialize
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
// client.println("GET /emoncms/post.php?json= HTTP/1.1"); // the HTTP request
// client.println("Host: www.toddknapek.com");
client.println("GET /search?q=arduino HTTP/1.1"); // the HTTP request
client.println();
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c); // echo all data received to the Serial Monitor
}
if (!client.connected()) {
Serial.println();
Serial.println("hmmm.");
client.stop();
for (;;)
;
}
}
I also tried zoomkat's example code, and it connected great to his server.... once. All subsequent attempts have been failures.
starting simple arduino client test
connecting...
connected
HTTP/1.1 200 OK
Date: Wed, 16 Nov 2011 07:47:12 GMT
Server: Apache
Last-Modified: Sat, 13 Nov 2010 16:31:40 GMT
Accept-Ranges: bytes
Content-Length: 51
Connection: close
Content-Type: text/plain; charset=UTF-8
Woohoo! Your arduino ethernet client works!
zoomkat
disconnecting.
==================================
starting simple arduino client test
connecting...
connection failed
disconnecting.
==================================
starting simple arduino client test
connecting...
connection failed
disconnecting.
==================================
Although, I'm not completely convinced that this is a firewall / router issue, as I also tried to connect to a Windows Home Server on my local network, and it displayed the exact same behavior - it connected perfectly the first time, and then failed on all subsequent attempts.
connecting...
connected
HTTP/1.1 404 Not Found
Content-Length: 1635
Content-Type: text/html
Server: Microsoft-IIS/6.0
X-Powered-By: ASP.NET
Date: Wed, 16 Nov 2011 07:56:40 GMT
Connection: close
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>The page cannot be found</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
<STYLE type="text/css">
BODY { font: 8pt/12pt verdana }
H1 { font: 13pt/15pt verdana }
H2 { font: 8pt/12pt verdana }
A:link { color: red }
A:visited { color: maroon }
</STYLE>
</HEAD><BODY><TABLE width=500 border=0 cellspacing=10><TR><TD>
<h1>The page cannot be found</h1>
The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.
<hr>
<p>Please try the following:</p>
<ul>
<li>Make sure that the Web site address displayed in the address bar of your browser is spelled and formatted correctly.</li>
<li>If you reached this page by clicking a link, contact
the Web site administrator to alert them that the link is incorrectly formatted.
</li>
<li>Click the <a href="javascript:history.back(1)">Back</a> button to try another link.</li>
</ul>
<h2>HTTP Error 404 - File or directory not found.
Internet Information Services (IIS)</h2>
<hr>
<p>Technical Information (for support personnel)</p>
<ul>
<li>Go to <a href="http://go.microsoft.com/fwlink/?linkid=8180">Microsoft Product Support Services</a> and perform a title search for the words <b>HTTP</b> and <b>404</b>.</li>
<li>Open <b>IIS Help</b>, which is accessible in IIS Manager (inetmgr),
and search for topics titled <b>Web Site Setup</b>, <b>Common Administrative Tasks</b>, and <b>About Custom Error Messages</b>.</li>
</ul>
</TD></TR></TABLE></BODY></HTML>
hmmm.
connecting...
connection failed
hmmm.
connecting...
connection failed
hmmm.
Any ideas on this one?
Thanks fellas.