Echo example of class C devices receiving downlink and sending as next uplink

Dependencies:   libmDot-mbed5 ISL29011

Revision:
12:ec9768677cea
Parent:
9:72d3203279b2
Child:
14:19fae4509473
--- a/examples/src/ota_example.cpp	Tue Oct 11 11:49:56 2016 -0500
+++ b/examples/src/ota_example.cpp	Tue Oct 11 13:17:42 2016 -0500
@@ -41,39 +41,44 @@
     
     dot = mDot::getInstance();
 
-    // make sure library logging is turned on
-    dot->setLogLevel(mts::MTSLog::INFO_LEVEL);
+    if (!dot->getStandbyFlag()) {
+        // start from a well-known state
+        logInfo("defaulting Dot configuration");
+        dot->resetConfig();
+        dot->resetNetworkSession();
 
-    // update configuration if necessary
-    if (dot->getJoinMode() != mDot::OTA) {
-        logInfo("changing network join mode to OTA");
-        if (dot->setJoinMode(mDot::OTA) != mDot::MDOT_OK) {
-            logError("failed to set network join mode to OTA");
+        // make sure library logging is turned on
+        dot->setLogLevel(mts::MTSLog::INFO_LEVEL);
+
+        // update configuration if necessary
+        if (dot->getJoinMode() != mDot::OTA) {
+            logInfo("changing network join mode to OTA");
+            if (dot->setJoinMode(mDot::OTA) != mDot::MDOT_OK) {
+                logError("failed to set network join mode to OTA");
+            }
         }
-    }
-    // in OTA and AUTO_OTA join modes, the credentials can be passed to the library as a name and passphrase or an EUI and KEY
-    // only one method or the other should be used!
-    // network ID = crc64(network name)
-    // network KEY = cmac(network passphrase)
-    update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, public_network, ack);
-    //update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack);
+        // in OTA and AUTO_OTA join modes, the credentials can be passed to the library as a name and passphrase or an ID and KEY
+        // only one method or the other should be used!
+        // network ID = crc64(network name)
+        // network KEY = cmac(network passphrase)
+        update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, public_network, ack);
+        //update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack);
     
-    // save changes to configuration
-    logInfo("saving configuration");
-    if (!dot->saveConfig()) {
-        logError("failed to save configuration");
-    }
+        // save changes to configuration
+        logInfo("saving configuration");
+        if (!dot->saveConfig()) {
+            logError("failed to save configuration");
+        }
 
-    // restore the saved session if the dot woke from deepsleep mode
-    // useful to use with deepsleep because session info is otherwise lost when the dot enters deepsleep
-    if (dot->getStandbyFlag()) {
+        // display configuration
+        display_config();
+    } else {
+        // restore the saved session if the dot woke from deepsleep mode
+        // useful to use with deepsleep because session info is otherwise lost when the dot enters deepsleep
         logInfo("restoring network session from NVM");
         dot->restoreNetworkSession();
     }
 
-    // display configuration
-    display_config();
-
     while (true) {
         uint16_t light;
         std::vector<uint8_t> tx_data;