mbed Sensor node for Instrumented Booth over ETH.
Dependencies: EthernetInterface-1 MaxbotixDriver Presence HTU21D_TEMP_HUMID_SENSOR_SAMPLE Resources SHARPIR mbed-rtos mbed-src WDT_K64F nsdl_lib
Fork of Trenton_Switch_LPC1768_ETH by
Diff: main.cpp
- Revision:
- 38:9066ab490386
- Parent:
- 35:b0c1b676403a
- Child:
- 46:807e9cf63f4c
--- a/main.cpp Tue Dec 16 12:26:35 2014 +0000 +++ b/main.cpp Thu Dec 18 08:55:33 2014 +0000 @@ -18,16 +18,16 @@ #include "nsdl_support.h" #include "node_cfg.h" #include "sensor_ctl.h" +#include "rtos.h" - +#include "Watchdog.h" //Serial pc(USBTX, USBRX); - +#define WATCHDOG_TIMEOUT_SEC 30 //30 seconds +#define HEARTBEAT_PERIOD_MS 1000 //1 second... // Ethernet initialization - EthernetInterface eth; - static void ethernet_init() { /* Initialize network */ @@ -55,7 +55,6 @@ Endpoint nsp; - /* The number of seconds between NSDL Ticks*/ #define NSDL_TICK_PERIOD_MS 1000 @@ -63,6 +62,9 @@ //For timing control // Timer nsdlTickTimer; Timer registrationTimer; + #if HEART_BEAT + Timer heartBeatTimer; + #endif //Sensor timers... #if NODE_SENSOR_STATION @@ -101,6 +103,9 @@ // nsdlTickTimer.start(); registrationTimer.start(); + #if HEART_BEAT + heartBeatTimer.start(); + #endif //Heartbeat #if NODE_SENSOR_STATION temperatureReportTimer.start(); microphoneSampleTimer.start(); @@ -118,8 +123,13 @@ heightReportTimer.start(); #endif //NODE HEIGHT STATION #endif //NODE_SENSOR_STATION - + DigitalOut led2(LED2); + //Watchdog wdt; +// wdt.kick(WATCHDOG_TIMEOUT_SEC); + NSP_registration(); while(true) { + //Kick the watchdog... +// wdt.kick(); //UDP Packet Receive... n = server.receiveFrom(from, buffer, sizeof(buffer)); if (n <= 0) { @@ -145,7 +155,13 @@ NSP_registration(); registrationTimer.reset(); } - + #if HEART_BEAT + if (heartBeatTimer.read_ms() >= HEARTBEAT_PERIOD_MS){ + //Toggle heartbeat led... + led2 = !led2; + heartBeatTimer.reset(); + } + #endif //HEart Beat #if NODE_SENSOR_STATION if (temperatureReportTimer.read_ms() >= TEMPERATURE_REPORT_PERIOD_MS){ //debug("Event: Temperature Report Timer\r\n"); @@ -209,6 +225,7 @@ nsdl_run(); //Init Sensors init_sensors(); + // Run the event loop (never returns) main_event_loop();