Skip to content

Commit

Permalink
Add Watchdog & minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanchantrell committed Sep 5, 2012
1 parent 5341c9b commit f21633e
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
21 changes: 13 additions & 8 deletions TinyTX_MAX1284_emoncms/TinyTX_MAX1284_emoncms.ino
Expand Up @@ -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

Expand Down Expand Up @@ -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

}

//--------------------------------------------------------------------
Expand All @@ -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();
Expand All @@ -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 ");
Expand Down Expand Up @@ -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

}

Expand Down
16 changes: 14 additions & 2 deletions TinyTX_NanodeRF_emoncms/TinyTX_NanodeRF_emoncms.ino
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f21633e

Please sign in to comment.