Go Down

Topic: Reset ethernet connection (Read 2026 times) previous topic - next topic

pauldreed

I am using this sketch https://gist.github.com/1130021 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?

Onions

Quote
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.
My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

pauldreed


Quote
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.

What is the actual  code to force a system reset?

Onions

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

Code: [Select]
#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.
My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

pauldreed


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

Code: [Select]
#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.

Onions

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

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

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.
My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

pauldreed


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?

Onions

Quote
Sorry for all the questions

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

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

http://arduino.cc/en/Reference/ClientConnect

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


Code: [Select]
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():
Code: [Select]
#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.
My website: http://www.harryrabbit.co.uk/electronics/home.html Up and running now! (Feel free to look round!) :D

pauldreed

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

pauldreed


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

http://arduino.cc/en/Reference/ClientConnect

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


Code: [Select]
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 http://arduino.cc/en/Reference/ClientConnect written just to work with the ethernet.h library?

PaulS

Quote
I am using the Ethercard.h library

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

pauldreed


Quote
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!

PaulS

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

pauldreed


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.

PaulS

Quote
a Nanode, which uses a ENC28J60 ethernet controller.

Ah. That makes it a lot tougher.

Go Up