I've been working this problem for the past several days and getting nowhere. This issue has come up before in the forum but none of the solutions are working for me. I have an ethernet shield mounted on an UNO. The micro-SD card section works fine but the ethernet section is another story. It is unable to establish a connection in the program below. The output from the program is:
Better client test 4/04/12
Send an e in serial monitor to test
read an 'e'
connection failed
disconnecting.
I ran IPCONFIG to determine the correct addresses.
The "byte dns[]" line has been commented out because it produces the following error:
"'byte dns []' redeclared as different kind of symbol"
although I've read that this line may not be necessary.
Also, there was no MAC address sticker on the ethernet card but I understand that this may also not be necessary.
Would appreciate any help you can offer on this.
//zoomkat 4-04-12
//simple client test
//for use with IDE 1.0
//open serial monitor and send an e to test
//for use with W5100 based ethernet shields
//note that the below bug fix may be required
// http://code.google.com/p/arduino/issues/detail?id=605
//the arduino lan IP address { 192, 168, 1, 102 } may need
//to be modified modified to work with your router.
#include <SPI.h>
#include <Ethernet.h>
byte mac[] = {
0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE }; //physical mac address
byte ip[] = {
192, 168, 1, 105 }; // ip in lan assigned to arduino
byte gateway[] = { 192, 168, 1, 1}; // internet access via router
//byte dns[] = { 192, 168, 1, 1 }; //use router ip
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
byte myserver[] = {
// 208, 104, 2, 86 }; // zoomkat web page server IP address
209, 191, 122, 70 }; // yahoo
EthernetClient client;
//////////////////////
void setup(){
pinMode(10, OUTPUT);//sets w5100chip
// digitalWrite(10,HIGH); // disables w5100
pinMode(4, OUTPUT); // sets SD chip
digitalWrite(4,HIGH);//disables SD chip
//Ethernet.begin(mac, ip);
Ethernet.begin(mac, ip, dns, gateway, subnet);
Serial.begin(9600);
Serial.println("Better client test 4/04/12"); // so I can keep track of what is loaded
Serial.println("Send an e in serial monitor to test"); // what to do to test
}
void loop(){
// check for serial input
if (Serial.available() > 0) //if something in serial buffer
{
byte inChar; // sets inChar as a byte
inChar = Serial.read(); //gets byte from buffer
if(inChar == 'e') // checks to see byte is an e
{
Serial.println("read an 'e'");
sendGET(); // call sendGET function below when byte is an e
}
}
}
//////////////////////////
void sendGET() //client function to send/receive GET request data.
{
if (client.connect(myserver, 80)) { //starts client connection, checks for connection
Serial.println("connected");
client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
client.println(); //end of get request
}
else {
Serial.println("connection failed"); //error message if no client connect
Serial.println();
}
while(client.connected() && !client.available()) delay(1); //waits for data
// add counter as an attempt to bail out if too much input comes in
//
int counter = 0;
while (client.connected() || client.available()) { //connected or data available
char c = client.read(); //gets byte from ethernet buffer
Serial.print(c); //prints byte to serial monitor
counter = counter + 1;
if (counter >= 500 ) {
exit;
}
}
Serial.println();
Serial.println("disconnecting.");
Serial.println("==================");
Serial.println();
client.stop(); //stop client
}