Go Down

Topic: Ethernet shield permanently returning 0.0.0.0 after working for a few hours (Read 4437 times) previous topic - next topic

Hi,

I am wondering if anyone has seen a similar issue. My Arduino UNO + Ethernet shield (R3) have been functioning for a few hours, i.e. sending GET request to my PHP/MySQL server and reading the response back. Then I added codes to toggle digital output pins 13 and 12 to control the LED's. After that, my Ethernet shield stops working, always returning 0.0.0.0 for Ethernet.localIP(). I have cold reset the Arduino and the Ethernet shield, and have also swapped another Arduino UNO. But it's still the same problem. It's as if the Ethernet shield has been permanently fried or something. I have ordered two more Ethernet shields, which will arrive in a week or so. In the meantime, does anyone have any suggestion for me to try? I read from another post that pin 4 and 13 should be left alone when using Ethernet shield. Another other pins I should avoid?

Thanks,
George

brunol949


Then I added codes to toggle digital output pins 13 and 12 to control the LED's. After that, my Ethernet shield stops working

Arduino communicates with both the W5100 and SD card using the SPI bus (through the ICSP header). This is on digital pins 11, 12, and 13

http://arduino.cc/en/Main/ArduinoEthernetShield
Le mie opere : Flusso correnti nell'impianto fotovoltaico http://arduino.webveneto.net/energy_control/     PING ed E.Mail http://arduino.web

Thanks. I will keep that in mind.

I received the other new Ethernet shield I have ordered. It started working right away, so that means my old Ethernet shield has stopped working for some reason. I will leave that for now.

On a separate note, I set up my board to report heartbeat event to the server every second. After running for ten hours, I noticed that  client.connect(server, 80) has failed 83 times (ranging from 5 minutes to 40 minutes). I am just wondering (1) if it's normal, and (2) if there is anything I can do to improve it. There is only one connection open.

Thanks,
George

SurferTim

That would not be normal for me. I ran a client test sending a request every 20 seconds for 18 hours with no fails. I have not tried every second tho. Maybe if you post your "heartbeat" code, someone might be able to help you.

Thanks. Here is my loop code. WATCHDOG_ENABLE is set to true. Basically I see this message "WATCHDOG connection failed" on the Arduino IDE every 5 to 40 minutes. My server also keeps track of any heartbeat interval that is longer than 3 seconds. The server record matches the printout on the Arduino IDE. I will try increasing the heartbeat interval to see if it makes any difference.

void loop()
{
  //reset watchdog
  if(WATCHDOG_ENABLE)
  {
    Serial.print("*");
    if (client.connect(server, 80))
    {     
        Serial.print("+");
        String myString = "GET /watchdog.php?ip=";
        myString += String(ip[0]) + "." + String(ip[1]) + "." + String(ip[2]) + "." + String(ip[3]) + ".";
        myString += " HTTP/1.0";
        client.println(myString); //php page invoking my web service
        client.println();
           
        //Connected - Read the page
        String pageValue = readPage(); //go and read the output
        httpParse(pageValue);
      }
      else
      {
        Serial.println("WATCHDOG connection failed");
      } 
  }
   
  delay(1000);
}

SurferTim

That should work perfect...as long as setup(), readPage(), and httpParse have no errors. But my crystal ball is in the shop for repairs!  ;)

edit: If you did not get the hint, post all the code.

Thanks, SurferTim. I just ran anther test with heartbeat interval increased to 10 seconds. Over the course of five hours, there were four connection failures - about one failure per 450 heartbeats. This is interesting because my previous test of one second interval in 10 hours yielded around one failure per 433 heartbeats. I agree. Something is fishy.

I have pasted my entire code below. Please note that I have external interrupts 0 and 1 enabled to read the Wiegand26 value from my RFID device. I will start another test with the external interrupts disabled to see if it makes any difference. I would appreciate any insight into the connection failure. Thanks.


#include <SPI.h>
#include <Ethernet.h>
#include <avr/wdt.h>

#define WATCHDOG_ENABLE 1

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 2, 50 }; //assigned arduino LAN IP address
byte server[] = { 192, 168, 2, 47 }; // laptop running apache LAN IP address
byte gateway[] = { 192, 168, 2, 1 }; // laptop running apache LAN IP address
byte subnet[] = { 255, 255, 255, 0 }; // laptop running apache LAN IP address
EthernetClient client;
char inString[32]; // string for incoming serial data
int stringPos = 0; // string index counter
boolean startRead = false; // is reading?

volatile unsigned long rfid = 0;
volatile int readCount = 0;
int watchdogCount = 0;

void DATA0(void) {
  readCount++;
  rfid = rfid << 1;
}

void DATA1(void) {
  readCount++;
  rfid = rfid << 1;
  rfid |= 1;
}

String readPage()
{
  //read the page, and capture & return everything between '{' and '}'

  stringPos = 0;
  memset( &inString, 0, 32 ); //clear inString memory

  while(true)
  {
    if (client.available()) {
      char c = client.read();

      if (c == '{' ) { //'{' is our begining character
        startRead = true; //Ready to start reading the part
      }else if(startRead){

        if(c != '}'){ //'}' is our ending character
          inString[stringPos] = c;
          stringPos ++;
        }else{
          //got what we need here! We can disconnect now
          startRead = false;
          client.stop();
          client.flush();
          //Serial.println("disconnecting.");
          return inString;
        }
      }
    }
  }
}
 
void httpParse(String command)
{
  if(command == "WATCHDOG_RESET")
  {
    //reset the watchdog timer
    wdt_reset();
  }
  else
  {
    Serial.println("error");
  }
}

void setup()

  if(WATCHDOG_ENABLE)
  {
    //enable watchdog timer to 8 seconds
    wdt_enable(WDTO_8S);
  }
 
  Serial.begin(9600);
     
  Ethernet.begin(mac, ip, gateway, subnet);
  Serial.println(Ethernet.localIP());
 
  readCount = 0;
  rfid = 0;
 
  attachInterrupt(0, DATA0, RISING);
  attachInterrupt(1, DATA1, RISING);
 
  Serial.println("starting arduino client for front entrance");
  Serial.println();
}

void loop()
{
  //reset watchdog
  if(WATCHDOG_ENABLE)
  {
    if(watchdogCount > 10)
    {
      Serial.print("*");
      if (client.connect(server, 80))
      {     
          Serial.print("+");
          String myString = "GET /watchdog.php?ip=";
          myString += String(ip[0]) + "." + String(ip[1]) + "." + String(ip[2]) + "." + String(ip[3]) + ".";
          myString += " HTTP/1.0";
          client.println(myString); //php page invoking my web service
          client.println();
             
          //Connected - Read the page
          String pageValue = readPage(); //go and read the output
          httpParse(pageValue);
         
          watchdogCount = 0;
      }
      else
      {
          Serial.println("WATCHDOG connection failed");
      } 
    }
    else
    {
      //reset the watchdog timer
      wdt_reset();
    }
   
    watchdogCount++;
  }
   
  delay(1000);
}

SurferTim

This is incorrect.
Code: [Select]
Ethernet.begin(mac, ip, gateway, subnet);
 Serial.println(Ethernet.localIP());


V1.0 uses a different format. If you specify more than just the ip, you must specify a dns server ip. Normally, if you do not plan on resolving any domain names, you can use the gateway for that ip. My routers will provide localnet ips with dns service.

Code: [Select]
Ethernet.begin(mac, ip, gateway, gateway, subnet);
 Serial.println(Ethernet.localIP());


edit: And you are not reading the response from the server. You requested the page. At least be polite enough to read it. You don't have to do anything with it. Let the server close the connection.

Code: [Select]
while(client.connected())
{
  // stay in this loop until the server closes the connection
  while(client.available())
  {
     client.read();
  }
}
// now close your end
client.stop();


Also, if your ethernet shield has a microSD card reader, you need to disable the SD SPI interface if you do not plan on using it. In setup() before Ethernet.begin() call:

Code: [Select]
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);



I tried all your suggestions, but I am still seeing connection failure periodically. I have another Ethernet shield coming next week. I will try that one to see if it makes any difference.

BTW, I noticed that on my setup after uploading, it takes several watchdog resets until the Arduino receives the first response from the server. Once the first response is received, everything runs fine (except for the periodic connection failure, but at least no watchdog reset). Have you seen similar issue in the past? Below is the log. Thanks.

======log=================
192.168.2.48
starting arduino client for front entrance

*192.168.2.48
starting arduino client for front entrance

*192.168.2.48
starting arduino client for front entrance

*192.168.2.48
starting arduino client for front entrance

*192.168.2.48
starting arduino client for front entrance

*192.168.2.48
starting arduino client for front entrance

*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*....

SurferTim

I have not seen that one. For some reason, the connection is failing. It will take about 20 seconds to return from the client.connect() routine if it cannot establish a connection to the server. The watchdog timer only waits 8 seconds, correct?

Maybe it is the ethernet shield. Post your results when you get the new shield.

edit: Check your ethernet shield carefully. There has been one case where the w5100 had pins solder jumpered. Take a look at the pics in this subject.
http://arduino.cc/forum/index.php/topic,90960.0.html

I got my other new Ethernet shield today. Unfortunately same result. I get about one connection failure every 10 minutes. Everything still runs (no watchdog reset). I am beginning to suspect that the culprit may be my server (connected via wifi) + router combination. I will find another PC and router to repeat the test. Thank you for your help.

gabalord

Hi daytrader.
Let me specify that I'm quite new to this world, so forgive me if say something really odd!

I've experienced the same problem as you posted:
ip 0.0.0.0
but I solved it by removing the SD card and reinserting it, then pushing the reset button.

A brief history.
I was using an old Arduino software (not sure which version) and all worked fine: happily connect to my arduino through Internet Browser.
Then I upgraded the software to 1.0.1.
Seems that some ethernet lib have changed.
The problem arises soon after (minutes) and I was no more able to gain access to my device through http 80.
If I ping the expected (encoded in the sketch) IP (192.168.1.177) I do have a response.
So there is some kind of communication between my router and the arduino device.
ARP -f show the mac id and the right IP.
Nevertheless the browser can't connect to the device and the serial monitor still show 0.0.0.0.

As I said...I just extracted and reinserted the SD card, and it start working again.
Not sure if this is the solution but it definitely have something to do with libraries and SD in my humble opinion.

Have Fun!

Gabriel




Hi Gabriel,

Thank you for your update. I forgot to post my result back to the forum. I was using a wireless laptop as my server. After replacing it with another server using Ethernet connection, the connection failure does not occur any more. Regarding the 0.0.0.0 IP address, I bought a new Ethernet shield, and it's working fine. So it's likely the old Ethernet shield just stopped working.

Thanks,
George

Go Up