From f21633e8294fde4b57ed845246cb14d4c5d0f60b Mon Sep 17 00:00:00 2001 From: Nathan Chantrell Date: Wed, 5 Sep 2012 01:01:49 +0100 Subject: [PATCH] Add Watchdog & minor tweaks --- .../TinyTX_MAX1284_emoncms.ino | 21 ++++++++++++------- .../TinyTX_NanodeRF_emoncms.ino | 16 ++++++++++++-- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/TinyTX_MAX1284_emoncms/TinyTX_MAX1284_emoncms.ino b/TinyTX_MAX1284_emoncms/TinyTX_MAX1284_emoncms.ino index b8abd28..d0b655a 100644 --- a/TinyTX_MAX1284_emoncms/TinyTX_MAX1284_emoncms.ino +++ b/TinyTX_MAX1284_emoncms/TinyTX_MAX1284_emoncms.ino @@ -15,6 +15,7 @@ #include // https://github.com/jcw/jeelib #include // https://bitbucket.org/homehack/ethernet52/src #include +#include // Fixed RF12 settings #define MYNODE 30 // node ID 30 reserved for base station @@ -22,7 +23,7 @@ #define group 210 // network group // emoncms settings, change these settings to match your own setup -#define SERVER "www.chantrell.net"; // emoncms server +#define SERVER "www.chantrell.net"; // emoncms server #define EMONCMS "emoncms" // location of emoncms on server, blank if at root #define APIKEY "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // API write key @@ -124,6 +125,9 @@ void setup () { #endif digitalWrite(ledPin,LOW); // Turn LED off to indicate setup has finished + + wdt_enable(WDTO_8S); // Enable the watchdog timer with an 8 second timeout + } //-------------------------------------------------------------------- @@ -132,6 +136,8 @@ void setup () { void loop () { + wdt_reset(); // Reset the watchdog timer + #ifdef USE_NTP if ((millis()-timeTX)>(NTP_PERIOD*60000)){ // Send NTP time getTime(); @@ -146,9 +152,9 @@ void loop () { if (rf12_recvDone() && rf12_crc == 0 && (rf12_hdr & RF12_HDR_CTL) == 0) { - digitalWrite(ledPin,HIGH); // Turn LED on int nodeID = rf12_hdr & 0x1F; // extract node ID from received packet rx=*(Payload*) rf12_data; // Get the payload + digitalWrite(ledPin,HIGH); // Turn LED on #ifdef DEBUG Serial.print("Data received from Node "); @@ -219,16 +225,15 @@ void loop () { delay(200); client.stop(); - digitalWrite(ledPin,LOW); // Turn LED OFF - dataReady = 0; // reset data ready flag - } - else { + } + else { #ifdef DEBUG Serial.println("connection failed"); #endif - delay(1000); // wait 1s before trying again - } + } + + digitalWrite(ledPin,LOW); // Turn LED OFF } diff --git a/TinyTX_NanodeRF_emoncms/TinyTX_NanodeRF_emoncms.ino b/TinyTX_NanodeRF_emoncms/TinyTX_NanodeRF_emoncms.ino index 3627ccd..c6805d3 100644 --- a/TinyTX_NanodeRF_emoncms/TinyTX_NanodeRF_emoncms.ino +++ b/TinyTX_NanodeRF_emoncms/TinyTX_NanodeRF_emoncms.ino @@ -8,20 +8,24 @@ //------------------------------------------------------------------------------------------------------------------------ #define DEBUG // uncomment for serial output (57600 baud) +#define OPTIBOOT // Use watchdog timer (for optiboot bootloader only) #include // https://github.com/jcw/jeelib #include // https://github.com/jcw/ethercard/tree/development dev version with DHCP fixes #include // https://github.com/thiseldo/NanodeMAC +#ifdef OPTIBOOT +#include +#endif + // Fixed RF12 settings #define MYNODE 30 // node ID 30 reserved for base station #define freq RF12_433MHZ // frequency #define group 210 // network group // emoncms settings, change these settings to match your own setup -#define SERVER "tardis.chantrell.net"; // emoncms server +#define SERVER "www.chantrell.net"; // emoncms server #define EMONCMS "emoncms" // location of emoncms on server, blank if at root -#define APIKEY "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" // API write key #define greenLedPin 5 // NanodeRF Green LED on Pin 5 #define redLedPin 6 // NanodeRF Red LED on Pin 6 @@ -113,10 +117,18 @@ void setup () { lastRF = millis()-40000; // Forces the a send straight away digitalWrite(redLedPin,HIGH); // Turn red LED off to indicate setup has finished + + #ifdef OPTIBOOT + wdt_enable(WDTO_8S); // Enable the watchdog timer with an 8 second timeout + #endif } void loop () { + + #ifdef OPTIBOOT + wdt_reset(); // Reset the watchdog timer + #endif //-------------------------------------------------------------------- // On data receieved from rf12