Permalink
Browse files

Add Watchdog & minor tweaks

  • Loading branch information...
1 parent 5341c9b commit f21633e8294fde4b57ed845246cb14d4c5d0f60b @nathanchantrell committed Sep 5, 2012
@@ -15,14 +15,15 @@
#include <JeeLib.h> // https://github.com/jcw/jeelib
#include <Ethernet52.h> // https://bitbucket.org/homehack/ethernet52/src
#include <EthernetUdp.h>
+#include <avr/wdt.h>
// 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 "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
}
@@ -8,20 +8,24 @@
//------------------------------------------------------------------------------------------------------------------------
#define DEBUG // uncomment for serial output (57600 baud)
+#define OPTIBOOT // Use watchdog timer (for optiboot bootloader only)
#include <JeeLib.h> // https://github.com/jcw/jeelib
#include <EtherCard.h> // https://github.com/jcw/ethercard/tree/development dev version with DHCP fixes
#include <NanodeMAC.h> // https://github.com/thiseldo/NanodeMAC
+#ifdef OPTIBOOT
+#include <avr/wdt.h>
+#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

0 comments on commit f21633e

Please sign in to comment.