Offline
Full Member
Karma: 0
Posts: 104
|
 |
« on: November 24, 2011, 02:43:20 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 104
|
 |
« Reply #2 on: November 24, 2011, 03:17:04 pm » |
What is the actual code to force a system reset?
|
|
|
|
|
Logged
|
|
|
|
|
Newcastle, England
Offline
Sr. Member
Karma: 2
Posts: 489
Always learning!
|
 |
« Reply #3 on: November 24, 2011, 03:21:02 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 104
|
 |
« Reply #4 on: November 24, 2011, 03:39:37 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Newcastle, England
Offline
Sr. Member
Karma: 2
Posts: 489
Always learning!
|
 |
« Reply #5 on: November 24, 2011, 03:44:29 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 104
|
 |
« Reply #6 on: November 24, 2011, 03:50:17 pm » |
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?
|
|
|
|
|
Logged
|
|
|
|
|
Newcastle, England
Offline
Sr. Member
Karma: 2
Posts: 489
Always learning!
|
 |
« Reply #7 on: November 24, 2011, 03:58:23 pm » |
Sorry for all the questions Don't worry, I don't mind!  how can you determine if a site (such as google.com) has loaded or not? http://arduino.cc/en/Reference/ClientConnectConnect 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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 104
|
 |
« Reply #8 on: November 24, 2011, 04:01:03 pm » |
Thanks for your help Onions, I'll have a try with this over the weekend.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 104
|
 |
« Reply #9 on: November 25, 2011, 01:58:46 pm » |
how can you determine if a site (such as google.com) has loaded or not? http://arduino.cc/en/Reference/ClientConnectConnect 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 http://arduino.cc/en/Reference/ClientConnect written just to work with the ethernet.h library?
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #10 on: November 25, 2011, 03:09:47 pm » |
I am using the Ethercard.h library So? Go look at the source code, and answer you own question.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 104
|
 |
« Reply #11 on: November 25, 2011, 03:13:35 pm » |
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!
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #12 on: November 25, 2011, 03:27:48 pm » |
Where did you get this Ethercard library? Perhaps someone else could have a look at it.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 0
Posts: 104
|
 |
« Reply #13 on: November 25, 2011, 03:41:35 pm » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #14 on: November 25, 2011, 03:50:23 pm » |
a Nanode, which uses a ENC28J60 ethernet controller. Ah. That makes it a lot tougher.
|
|
|
|
|
Logged
|
|
|
|
|
|