trash over HTTP

Dependencies:   C027_Support HTTPClient TrashSensors mbed Crypto

Fork of SLOTrashHTTP by Corey Ford

Collects sensor readings and sends them to https://trash.coreyford.name/

Server code: https://github.com/coyotebush/trash-map

Files at this revision

API Documentation at this revision

Comitter:
coyotebush
Date:
Thu Jun 04 04:59:57 2015 +0000
Parent:
6:43ac8ef67a03
Child:
8:2398817ac9c2
Commit message:
Add watchdog

Changed in this revision

Watchdog.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Watchdog.h	Thu Jun 04 04:59:57 2015 +0000
@@ -0,0 +1,24 @@
+#ifndef WATCHDOG_H
+#define WATCHDOG_H
+
+// https://developer.mbed.org/cookbook/WatchDog-Timer
+
+class Watchdog {
+public:
+// Load timeout value in watchdog timer and enable
+    void kick(float s) {
+        LPC_WDT->WDCLKSEL = 0x1;                // Set CLK src to PCLK
+        uint32_t clk = SystemCoreClock / 16;    // WD has a fixed /4 prescaler, PCLK default is /4
+        LPC_WDT->WDTC = s * (float)clk;
+        LPC_WDT->WDMOD = 0x3;                   // Enabled and Reset
+        kick();
+    }
+// "kick" or "feed" the dog - reset the watchdog timer
+// by writing this required bit pattern
+    void kick() {
+        LPC_WDT->WDFEED = 0xAA;
+        LPC_WDT->WDFEED = 0x55;
+    }
+};
+
+#endif
\ No newline at end of file
--- a/main.cpp	Sun May 31 22:25:25 2015 +0000
+++ b/main.cpp	Thu Jun 04 04:59:57 2015 +0000
@@ -5,6 +5,8 @@
 #include "GroveTemp.h"
 #include "GPS.h"
 
+#include "Watchdog.h"
+
 #include "SHA1.h"
 #include "HMAC.h"
 
@@ -31,6 +33,8 @@
     mbed_mac_address(macAddress);
     printf("MAC address is %02X%02X%02X%02X%02X%02X\r\n", macAddress[0], macAddress[1], macAddress[2], macAddress[3], macAddress[4], macAddress[5]);
     
+    Watchdog wdt;
+    
     GPSSerial gps;
 
 #ifdef CELLULAR_NETWORK
@@ -59,6 +63,8 @@
     GroveTempSensor tempS;
     double tempV;
     
+    wdt.kick(30.0);
+    
     while (true) {
         // Distance sensor
         distS.start();
@@ -88,6 +94,7 @@
                 break;
             }
         }
+        wdt.kick();
         
         // Combine readings in JSON
         char json[255];
@@ -126,6 +133,8 @@
         }
         
         first = false;
+        wdt.kick();
         wait_ms(10000);
+        wdt.kick();
     }
 }