Ethernet shield freezes

Hi,

I own this kit: http://www.sainsmart.com/arduino/arduino-kits/mega-r3-smartkits/sainsmart-mega2560-r3-ethernet-shield-kit-for-arduino-atmega8u2-w5100.html

Using these devices I have built a base station for wireless sensor nodes (with RFM12B). It works well for approximately 6h. After that the code seems to freeze and the LED next to pin 10 blinks rapidly. Reset does not help. When I remove the power source and reattach it, everything starts to work again. My code can be seen here: http://pastebin.com/ytdVHqtu

LED labels on my ethernet shield are fuzzy. Can anyone tell me what indicator LED is next to pin 10? Rightmost on this image: http://www.sainsmart.com/zen/albums/SKU/20/20-011/20-011-C83/20-011-C83/06.JPG

Ideas why the code freezes are also very welcome :)

If anyone suggests some good site where schematic can be drawn online then I can create that scetch as well...

Do you have the serial monitor open when the fail occurs? What is the last thing displayed?

If you need a comparative test, I have my ethernet client code on the playground. It has all the "antifreeze" functions in it I could find. Give it a try and see if it locks up also. http://playground.arduino.cc/Code/WebClient

I have run it for days without failure or lockups, and I torture it by disconnecting the cat5, power cycle the router, disable the server, etc, and it keeps running.

I was able to reproduce with serial monitor open. The last log lines were: "OK recieved" and response message "ok" meaning it reached line 254 (http://pastebin.com/ytdVHqtu).

Also indicator LED is turned off meaning it didn't reach next loop execution start where LEDpin is set HIGH again.

Then these are both evaluating to false or you would get "disconnecting" or "Connecting". I would guess that "client.connected()" is evaluating to true, so "!client.connected()" would evaluate to false.

  if (!client.connected() && lastConnected) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
  }

  if (!client.connected() && data_ready) {
   Serial.println("Connecting");

Check client.connected() like this at line 256 (after the "ok" print at line 254)

if(client.connected()) Serial.println("connected");
else Serial.println("not connected");

When everything freezes after working stable for a while pin 13 blinks rapidly although I'm not even using it in my scetch... What could this error indicate?

mudem:
When everything freezes after working stable for a while pin 13 blinks rapidly although I’m not even using it in my scetch… What could this error indicate?

It could indicate that the D13 pin is floating and oscillating wildly. Set D13 as an OUTPUT and LOW in your setup function. It should be LOW by default, but I always make sure just in case.

pinMode(13, OUTPUT);
digitalWrite(13, LOW);

Does that stop the blinking?

What is the rf12 device? Is it connected also? Is it this device?

Did you notice it is also uses a SPI bus? How is it wired to the Mega/shield?

mudem: When everything freezes after working stable for a while pin 13 blinks rapidly although I'm not even using it in my scetch... What could this error indicate?

I think arduino pin 13 is used for a clocking pin by the Ethernet shield. It may look some what dim when the Ethernet shield is in use (as opposed to a blink sketch) as it is actually blinking on/off very fast.

zoomkat:

mudem: When everything freezes after working stable for a while pin 13 blinks rapidly although I'm not even using it in my scetch... What could this error indicate?

I think arduino pin 13 is used for a clocking pin by the Ethernet shield. It may look some what dim when the Ethernet shield is in use (as opposed to a blink sketch) as it is actually blinking on/off very fast.

It's a Mega 2560. That model doesn't use D13 for the SPI clock. It uses D52.

SurferTim:

mudem:
When everything freezes after working stable for a while pin 13 blinks rapidly although I’m not even using it in my scetch… What could this error indicate?

It could indicate that the D13 pin is floating and oscillating wildly. Set D13 as an OUTPUT and LOW in your setup function. It should be LOW by default, but I always make sure just in case.

pinMode(13, OUTPUT);

digitalWrite(13, LOW);



Does that stop the blinking?

What is the rf12 device? Is it connected also? Is it this device?
https://www.sparkfun.com/datasheets/Wireless/General/RF12B-IC.pdf
Did you notice it is also uses a SPI bus? How is it wired to the Mega/shield?

rf12 device: http://nathan.chantrell.net/tinytx-wireless-sensor/
It is connected to pins 50, 51, 52 and SS is connected not to pin 53 but to pin 11. This is configured just before initialize rf12_set_cs(11);

Have you tried the ethernet shield by itself without the rf12 device to insure they are not conflicting somehow?

Seems that watchdog bit me. This came along with some code I took from GitHub. Disabled it and seems to be running stable now.

Still hangs eventually :( But now I have new debugging results. I added few leds to the mix and using this code: http://pastebin.com/B344fJYX I was able to find that the code freezes somewhere between lines 276 and 288 because both pin 7 and 8 are high and this ony happens in those lines.

Before the issue was probably the same but because the code had watchdog it reseted Arduino when this was detected. Seems like emoncms.org just does not accept data coming from client.print and thus ethernet code remains stuck.

How to debug this further?

Maybe you are running out of SRAM memory?

Is the last thing you see on the serial monitor “Sending:” with your variables appended?