fp

Dependencies:   libmDot-mbed5 ISL29011

Revision:
12:ec9768677cea
Parent:
9:72d3203279b2
Child:
14:19fae4509473
--- a/examples/src/manual_example.cpp	Tue Oct 11 11:49:56 2016 -0500
+++ b/examples/src/manual_example.cpp	Tue Oct 11 13:17:42 2016 -0500
@@ -38,44 +38,50 @@
     
     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::MANUAL) {
-        logInfo("changing network join mode to MANUAL");
-        if (dot->setJoinMode(mDot::MANUAL) != mDot::MDOT_OK) {
-            logError("failed to set network join mode to MANUAL");
+        // make sure library logging is turned on
+        dot->setLogLevel(mts::MTSLog::INFO_LEVEL);
+
+        // update configuration if necessary
+        if (dot->getJoinMode() != mDot::MANUAL) {
+            logInfo("changing network join mode to MANUAL");
+            if (dot->setJoinMode(mDot::MANUAL) != mDot::MDOT_OK) {
+                logError("failed to set network join mode to MANUAL");
+            }
         }
-    }
-    // in MANUAL join mode there is no join request/response transaction
-    // as long as the Dot is configured correctly and provisioned correctly on the gateway, it should be able to communicate
-    // network address - 4 bytes (00000001 - FFFFFFFE)
-    // network session key - 16 bytes
-    // data session key - 16 bytes
-    // to provision your Dot with a Conduit gateway, follow the following steps
-    //   * ssh into the Conduit
-    //   * provision the Dot using the lora-query application: http://www.multitech.net/developer/software/lora/lora-network-server/
-    //      lora-query -a 01020304 A 0102030401020304 <your Dot's device ID> 01020304010203040102030401020304 01020304010203040102030401020304
-    //   * if you change the network address, network session key, or data session key, make sure you update them on the gateway
-    // to provision your Dot with a 3rd party gateway, see the gateway or network provider documentation
-    update_manual_config(network_address, network_session_key, data_session_key, frequency_sub_band, public_network, ack);
+        // in MANUAL join mode there is no join request/response transaction
+        // as long as the Dot is configured correctly and provisioned correctly on the gateway, it should be able to communicate
+        // network address - 4 bytes (00000001 - FFFFFFFE)
+        // network session key - 16 bytes
+        // data session key - 16 bytes
+        // to provision your Dot with a Conduit gateway, follow the following steps
+        //   * ssh into the Conduit
+        //   * provision the Dot using the lora-query application: http://www.multitech.net/developer/software/lora/lora-network-server/
+        //      lora-query -a 01020304 A 0102030401020304 <your Dot's device ID> 01020304010203040102030401020304 01020304010203040102030401020304
+        //   * if you change the network address, network session key, or data session key, make sure you update them on the gateway
+        // to provision your Dot with a 3rd party gateway, see the gateway or network provider documentation
+        update_manual_config(network_address, network_session_key, data_session_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;