Ethernet examples not working in 1.0

Hello all,

I have been using my duemilanove with wiznet ethernet shield with alot of projects while running 0022, but now that I have upgraded to 1.0 I can’t seem to get it to work.

The most life I have gotten out of it with 1.0 was mod’ing the webclient example to use a fixed ip address. but the output of making a web call to google was:

connecting...
connected
 request.  <ins>Thatâ??s all we know.</ins>
Ê?Õ¡EÆ?BÑ?%óBáC;?l&»ôX?+AÆV-Æ~Ìdx):Ól|?<??ð??EñÄéAým?ªó?
disconnecting.

any ideas?

Sol

The examples supplied with the 1.0 IDE should work. the release notes have some info on the changes. You can try the below code to see if it works for you.

//zoomkat 2-13-12
//DNS and DHCP-based web client test code
//for use with IDE 1.0
//open serial monitor and send an e to test
//and to see test result
//for use with W5100 based ethernet shields
//browser equivelant URL: 
//http://web.comporium.net/~shb/arduino.txt

#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
char serverName[] = "web.comporium.net"; // zoomkat's test web page server
EthernetClient client;

//////////////////////

void setup(){
  Serial.begin(9600); 
  Serial.println("DNS and DHCP-based web client test 2/13/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
  // 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:
    while(true);
  }
  // print your local IP address:
  Serial.print("Arduino IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
    Serial.print("."); 
  }
  Serial.println();
  Serial.println();
}

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
    {
      sendGET(); // call sendGET function below when byte is an e
    }
  }  
} 

//////////////////////////

void sendGET() //client function to send/receive GET request data.
{
  if (client.connect(serverName, 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
  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 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

Thanks Zoomkat,

I get this out over serial

DNS and DHCP-based web client test 2/13/12
Send an e in serial monitor to test

Then it hangs and I get nothing more out of it :confused: (even if I send an e)

Thanks

Sol

Do you know if there is a dhcp server on that localnet? If zoomkat's code did not display the dynamic ip assignment in the serial monitor, it probably did not get one.

Here is the new format for assigning a static ip in V1.0

// add these variable declarations changed for your localnet
IPAddress ip(192,168,0,2);
IPAddress subnet(255,255,255,0);
IPAddress gateway(192,168,0,1);
// if your router takes care of dns, this should work
// if not, use the dns server ip setting in your other network computers
IPAddress dns(192,168,0,1);

// in setup()
Ethernet.begin(mac,ip,dns,gateway,subnet);

edit: My bad. I used periods instead of commas in the dns ip. I changed them to commas.

Hi Tim,

Made the changes you suggested, this is the output I get (passed it an e as requested)

DNS and DHCP-based web client test 2/13/12
Send an e in serial monitor to test
Arduino IP address: 192.168.5.30.

connected

disconnecting.
==================

so it still doesn't seem to be getting a correct connection. Its odd as now it should be pretty much the same as using a fixed IP with the ethernet examples from 0022 ide, and its still now working :confused:

Thanks for the help so far!

Sol

edit: all my other devices running off this switch use DHCP for IPs, just renewed an address on one of them to check its still up and running

edit edit: I can ping the arduino on the network too from my computer

You are connecting, but not getting the text from his site.

I don't use this:

while(client.connected() && !client.available()) delay(1); //waits for data
  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 
  }

I use this instead:

while(client.connected())
{
   while(client.available())
   {
      Serial.write(client.read());
   }
}

That is about all I can suggest.

Simpler client code to try.

//zoomkat 12-08-11
//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

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 192, 168, 1, 102 }; // ip in lan assigned to arduino
//byte gateway[] = { 192, 168, 1, 1 }; // internet access via router
//byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
byte myserver[] = { 208, 104, 2, 86 }; // zoomkat web page server IP address
EthernetClient client;
//////////////////////

void setup(){

  Ethernet.begin(mac, ip);
  //Ethernet.begin(mac, ip, subnet, gateway);
  Serial.begin(9600); 
  Serial.println("Better client test 12/01/11"); // 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
    {
      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
  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 
  }

  Serial.println();
  Serial.println("disconnecting.");
  Serial.println("==================");
  Serial.println();
  client.stop(); //stop client

}

Ok, so I seem to be one step closer, I now get this output streaming till I reset:

just to note, from what I can see they are the same in ways that matter, butI'm using the ethernet shield one revision before the current.

Sol

Below is the return to the serial monitor when the code I posted works:

Better client test 12/01/11
Send an e in serial monitor to test
connected
HTTP/1.1 200 OK
Date: Fri, 17 Feb 2012 15:11:41 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.

I believe you that the code works :slight_smile:

I just don't understand how it can't for me... Can I ask what OS your running and version of gcc-avr? I run Linux, but don't have a windows or mac to test on.

Will try a fresh copy of the arduino ide (not that I have done much with this one) and see if that makes any difference.

Thanks for your help

Sol

...and it goes on forever, correct? I recognize that.

His code works, but the v1.0 ethernet library still has the now infamous "605 Bug". It will require a modification to the w5100.h file.
http://code.google.com/p/arduino/issues/detail?id=605

I'm still waiting for the new release that has a fix.

That fixed it!

Thanks both for your trouble shooting, I would still be tearing my hair out if it wasn’t for you.

I eagerly await arduino 1.0.1 with the fix built in.

Thanks again,

Solexious