SEAN O CONNELL / thermostat_fan_demo-sensor_battery-3

Dependencies:   PinDetect libmDot mbed-rtos mbed-src

Fork of thermostat_fan_demo-sensor_battery-2 by SEAN O CONNELL

Files at this revision

API Documentation at this revision

Comitter:
socie123
Date:
Tue Nov 03 23:42:53 2015 +0000
Parent:
2:8fd3285d3395
Commit message:
added sleep mode

Changed in this revision

thermostat_fan_demo-sensor-d55b476ea5e6/main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 8fd3285d3395 -r a138e64a37c4 thermostat_fan_demo-sensor-d55b476ea5e6/main.cpp
--- a/thermostat_fan_demo-sensor-d55b476ea5e6/main.cpp	Sat Oct 31 03:26:02 2015 +0000
+++ b/thermostat_fan_demo-sensor-d55b476ea5e6/main.cpp	Tue Nov 03 23:42:53 2015 +0000
@@ -82,6 +82,19 @@
     setFrequencySubBand(config_frequency_sub_band);
     setPower(7);    // Reduce latency for 868 units
     setAck(0);      // Disable ack for less latency
+    
+        // set join mode to AUTO_OTA so the mDot doesn't have to rejoin after sleeping
+    int32_t returnCode;
+    logInfo("setting join mode to AUTO_OTA");
+    if ((returnCode = dot->setJoinMode(mDot::AUTO_OTA)) != mDot::MDOT_OK) {
+        logError("failed to set join mode %d:%s", returnCode, mDot::getReturnCodeString(returnCode).c_str());
+    }
+    
+    // save this configuration to the mDot's NVM
+    logInfo("saving config");
+    if (! dot->saveConfig()) {
+        logError("failed to save configuration");
+}
 
     while (!joinNetwork()) { wait(2); dot->resetNetworkSession(); }
 
@@ -167,6 +180,7 @@
     }   
 }
 
+
 void ledTock() {
     transmitLED = !transmitLED;
    buttonPressLED = !buttonPressLED;
@@ -258,7 +272,6 @@
     return true;
 }
 
-
 bool joinNetwork()
 {
     int32_t returnCode;
@@ -300,12 +313,13 @@
         return false;
     }
     printf("Data sent!\r\n");
+    
          // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again
-    //uint32_t sleep_time = std::max((uint32_t)10000, (uint32_t)dot->getNextTxMs()) / 1000;
-    //logInfo("going to sleep...");
+    uint32_t sleep_time = std::max((uint32_t)8000, (uint32_t)dot->getNextTxMs()) / 1000;
+    logInfo("going to sleep...");
  
     // go to deepsleep and wake up automatically sleep_time seconds later
-    //ot->sleep(sleep_time, mDot::RTC_ALARM);
+    dot->sleep(sleep_time, mDot::RTC_ALARM);
  
     // go to deepsleep and wake up on rising edge of WKUP pin (PA0/XBEE_CTS/XBEE_DIO7)
     // dot->sleep(0, mDot::INTERRUPT);