Reset ethernet connection

I am using this sketch Example to use EtherCard on Nanode to upload data to Pachube · GitHub to send data from my Nanode to Pachube, which generally works well, although have noticed that if my broadband connection drops out for a minute or two (my ISP is rubbish!!), the Nanode does not resume sending data without physically resetting it.
I was thinking of some sort of Watchdog, which could in effect reset the Nanode or re-establish the connection with my router, so I don't have to reset it manually.
Even something that resets it every hour regardless.
Is there a way to achieve this, to either reboot the Nanode, or re-load the code which establishes a fresh connection?

Is there a way to achieve this, to either reboot the Nanode, or re-load the code which establishes a fresh connection?

http://www.google.co.uk/search?q=avr+watchdog+timer&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-GB:official&client=firefox-a

Lots of ways! You'll want to set up a watchdog timer, then re-set it whenever there is a connection. That way, when the connection stops and the watchdog is not reset, it'll reset the actual board.

Onions.

Onions:

Is there a way to achieve this, to either reboot the Nanode, or re-load the code which establishes a fresh connection?

avr watchdog timer - Google Search

Lots of ways! You'll want to set up a watchdog timer, then re-set it whenever there is a connection. That way, when the connection stops and the watchdog is not reset, it'll reset the actual board.

Onions.

What is the actual code to force a system reset?

http://tushev.org/articles/electronics/48-arduino-and-watchdog-timer

#include <avr/wdt.h>  // include the library

void setup(){
  wdt_enable(WDTO_2S);  //Set up the watchdog timer. If it isn't reset every 2 seconds, the arduino will reset
}

void loop(){
  wdt_reset();  //Reset the watchdog
}

Onions.

Onions:
tushev.org // Simon Tushev

#include <avr/wdt.h>  // include the library

void setup(){
  wdt_enable(WDTO_2S);  //Set up the watchdog timer. If it isn't reset every 2 seconds, the arduino will reset
}

void loop(){
  wdt_reset();  //Reset the watchdog
}





Onions.

Thanks Onions
So the wdt_reset(); command in the loop actually stops the reset from occurring.
I could therefore write a IF/ELSE statement that normally runs the wdt_reset(); command, but say every hour it runs delay(3000) instead which should provide sufficient time for the reset to occur.

So the wdt_reset(); command in the loop actually stops the reset from occurring.

Yes, resetting the watchdog timer prevents the arduino from resetting.

I could therefore write a IF/ELSE statement that normally runs the wdt_reset(); command, but say every hour it runs delay(3000) instead which should provide sufficient time for the reset to occur.

Personally, I'd try and connect to a website (any would do) every few minutes. If there is no connection, the site will not load. If the site does not load, then you do not reset the watchdog and the board will reset. Doing it every hour has the disadvantage that if the connection drops at the start of the hour, that's a full hour to wait before it will work again...

Onions.

Onions:
Personally, I'd try and connect to a website (any would do) every few minutes. If there is no connection, the site will not load. If the site does not load, then you do not reset the watchdog and the board will reset. Doing it every hour has the disadvantage that if the connection drops at the start of the hour, that's a full hour to wait before it will work again...

Onions.

Sorry for all the questions... but how can you determine if a site (such as google.com) has loaded or not?

Sorry for all the questions

Don't worry, I don't mind! :slight_smile:

how can you determine if a site (such as google.com) has loaded or not?

Connect to the IP address and port specified in the constructor. The return value indicates success or failure.

if(!client.connect(  [google]  ){ //See if you can connect Note that you'll need to change [google] to google's URL/IP address
  connected = false;     //Not really needed, but it could be used if you decided on a different use...
  while(true);    //Do nothing for ever more. In reality, the watchdog will kick in and reset the board.
}

Have a look at the example for client.connect():

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 177 };
byte server[] = { 64, 233, 187, 99 }; // Google

Client client(server, 80);

void setup()
{
  Ethernet.begin(mac, ip);
  Serial.begin(9600);

  delay(1000);

  Serial.println("connecting...");

  if (client.connect()) {
    Serial.println("connected");
    client.println("GET /search?q=arduino 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(;;)
      ;
  }
}

Onions.

Thanks for your help Onions, I'll have a try with this over the weekend.

Onions:

how can you determine if a site (such as google.com) has loaded or not?

Ethernet - Arduino Reference

Connect to the IP address and port specified in the constructor. The return value indicates success or failure.

if(!client.connect(  [google]  ){ //See if you can connect Note that you'll need to change [google] to google's URL/IP address

connected = false;     //Not really needed, but it could be used if you decided on a different use...
  while(true);    //Do nothing for ever more. In reality, the watchdog will kick in and reset the board.
}




Onions.

I am using the Ethercard.h library, not the Ethernet.h library, will the client.connect command still work with Ethercard, or is the example at Ethernet - Arduino Reference written just to work with the ethernet.h library?

I am using the Ethercard.h library

So? Go look at the source code, and answer you own question.

PaulS:

I am using the Ethercard.h library

So? Go look at the source code, and answer you own question.

Tried that already Paul and couldn't find it, but thought that maybe some similar function/command would be in the library?
...but lack of experience/knowledge has been a barrier!

Where did you get this Ethercard library? Perhaps someone else could have a look at it.

PaulS:
Where did you get this Ethercard library? Perhaps someone else could have a look at it.

I got it from Jeelabs, http://jeelabs.net/projects/cafe/repository/entry/EtherCard/EtherCard.h.
I can't use the ethernet.h library because I'm using it on a Nanode, which uses a ENC28J60 ethernet controller.

a Nanode, which uses a ENC28J60 ethernet controller.

Ah. That makes it a lot tougher.

PaulS:

a Nanode, which uses a ENC28J60 ethernet controller.

Ah. That makes it a lot tougher.

The ethercard library works very well though and sends energy data to Pachube https://pachube.com/feeds/34843, but I want to develop a Watchdog to reboot the Nanode if the DHCP/DNS gets screwed up (which happens if my internet connection is temporarily lost).
A colleague has just emailed my and suggested the possibility of using Pachube's return HTTP status code, i.e. Pachube sends a 200 for OK, 404 for not found etc. instead of accessing a website such as google.com, but either would do.