I have been trying to get my arduino talk over ethernet consistently. I started with the WebClient example and I seem to get "connection failed" randomly.
Any ideas?
I have been trying to get my arduino talk over ethernet consistently. I started with the WebClient example and I seem to get "connection failed" randomly.
Any ideas?
See if the below works consistantly. Once the serial monitor is open, pushing the arduino reset button will reset the arduino and it will download again.
//zoomkat 11-13-10
//simple ethernet client test code
//for use with IDE 0021 and W5100 ethernet shield
//modify the arduino lan ip address as needed
//open serial monitor and push reset button to
//see what the arduino receives
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 102 };
byte server[] = { 208, 104, 2, 86 }; // zoomkat
Client client(server, 80);
void setup()
{
Ethernet.begin(mac, ip);
Serial.begin(9600);
Serial.println("starting simple arduino client test");
Serial.println();
delay(1000);
Serial.println("connecting...");
if (client.connect()) {
Serial.println("connected");
client.println("GET /~shb/arduino.txt HTTP/1.0");
client.println();
} else {
Serial.println("connection failed");
}
}
void loop()
{
if (client.available()) {
char c = client.read();
Serial.print(c);
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
for(;;);
}
}
That is what i get back after initial upload:
starting simple arduino client test
connecting...
connected
ª/??
disconnecting.
That is what i get back after a reset, the gibberish characters seem to be coming in forever:
starting simple arduino client test
connecting...
connected
ÿô?ÿ—Ì&·yÁúð?ìÿ³5üçü~îü»??§Ô7?ÐÆùæÉéðëëè¶Î
ª”æüȧùôáç´Í½^Ù(Óÿ®Ñ?ïıËï6Ѥï?Îæö?Äkð«(û?
After that I unplug the device and plug it back in:
starting simple arduino client test
connecting...
connection failed
disconnecting
I reset the board and i get:
starting simple arduino client test
connecting...
connected
HTTP/1.1 200 OK
Date: Fri, 19 Nov 2010 00:40:36 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.
Is this how the Ethernet shield is supposed to work?
Something you may be encountering if your ethernet shield is connected to a router is the connection communications between the router and the shield when the shield becomes active. What are you unplugging, the serial cable between the pc and arduino, or the ethernet cable?
Thanks zoomkat. I took your code and expanded on it slowly to get it to what I wanted. Not sure what I was doing wrong before.