Here it is ...

Dependencies:   libxDot-mbed5 TSL2561

Fork of Dot-Examples by MultiTech

Revision:
31:b990f61b9ee0
Parent:
30:0059ae42ff02
Child:
32:cc05a2e80969
--- a/examples/src/ota_example.cpp	Wed Jun 06 20:04:20 2018 +0000
+++ b/examples/src/ota_example.cpp	Wed Jul 11 13:40:54 2018 -0400
@@ -41,121 +41,124 @@
 mDot* dot = NULL;
 lora::ChannelPlan* plan = NULL;
 
-Serial pc(USBTX, USBRX);
+
+Serial pc(PA_9, PA_10);
 
 int main() {
-    pc.printf("main started \r\n");
-    // Custom event handler for automatically displaying RX data
-    RadioEvent events;
-
-    pc.baud(115200);
-    pc.printf("baud rate set \r\n");
-
-    mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
-    
+  pc.baud(115200);
+  pc.printf("main started \r\n");
+  // Custom event handler for automatically displaying RX data
+  RadioEvent events;
+  
+  
+  
+  pc.printf("baud rate set \r\n");
+  
+  mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
+  
 #if CHANNEL_PLAN == CP_US915
-    plan = new lora::ChannelPlan_US915();
+  plan = new lora::ChannelPlan_US915();
 #elif CHANNEL_PLAN == CP_AU915
-    plan = new lora::ChannelPlan_AU915();
+  plan = new lora::ChannelPlan_AU915();
 #elif CHANNEL_PLAN == CP_EU868
-    plan = new lora::ChannelPlan_EU868();
+  plan = new lora::ChannelPlan_EU868();
 #elif CHANNEL_PLAN == CP_KR920
-    plan = new lora::ChannelPlan_KR920();
+  plan = new lora::ChannelPlan_KR920();
 #elif CHANNEL_PLAN == CP_AS923
-    plan = new lora::ChannelPlan_AS923();
+  plan = new lora::ChannelPlan_AS923();
 #elif CHANNEL_PLAN == CP_AS923_JAPAN
-    plan = new lora::ChannelPlan_AS923_Japan();
+  plan = new lora::ChannelPlan_AS923_Japan();
 #elif CHANNEL_PLAN == CP_IN865
-    plan = new lora::ChannelPlan_IN865();
+  plan = new lora::ChannelPlan_IN865();
 #endif
-    assert(plan);
-
-    dot = mDot::getInstance(plan);
-    assert(dot);
-
-    // attach the custom events handler
-    dot->setEvents(&events);
-
-    if (!dot->getStandbyFlag()) {
-        logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION);
-
-        // start from a well-known state
-        logInfo("defaulting Dot configuration");
-        dot->resetConfig();
-        dot->resetNetworkSession();
-
-        // 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 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);// use the line below
-        update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack); ///
-
-        // configure network link checks
-        // network link checks are a good alternative to requiring the gateway to ACK every packet and should allow a single gateway to handle more Dots
-        // check the link every count packets
-        // declare the Dot disconnected after threshold failed link checks
-        // for count = 3 and threshold = 5, the Dot will ask for a link check response every 5 packets and will consider the connection lost if it fails to receive 3 responses in a row
-        update_network_link_check_config(3, 5);
-
-        // enable or disable Adaptive Data Rate
-        dot->setAdr(adr);
-
-        // Configure the join delay
-        dot->setJoinDelay(join_delay);
-
-        // save changes to configuration
-        logInfo("saving configuration");
-        if (!dot->saveConfig()) {
-            logError("failed to save configuration");
-        }
-
-        // 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();
+  assert(plan);
+  
+  dot = mDot::getInstance(plan);
+  assert(dot);
+  
+  // attach the custom events handler
+  dot->setEvents(&events);
+  
+  if (!dot->getStandbyFlag()) {
+    logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION);
+    
+    // start from a well-known state
+    logInfo("defaulting Dot configuration");
+    dot->resetConfig();
+    dot->resetNetworkSession();
+    
+    // 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");
+      }
     }
-
-    uint8_t counter = 0;
-    while (true) {
-        std::vector<uint8_t> tx_data;
-
-        // join network if not joined
-        if (!dot->getNetworkJoinStatus()) {
-            join_network();
-        }
-
-        tx_data.push_back(++counter);
-        logInfo("sending uplink with data = %d", counter);
-        send_data(tx_data);
-
-        // if going into deepsleep mode, save the session so we don't need to join again after waking up
-        // not necessary if going into sleep mode since RAM is retained
-        if (deep_sleep) {
-            logInfo("saving network session to NVM");
-            dot->saveNetworkSession();
-        }
-
-        // ONLY ONE of the three functions below should be uncommented depending on the desired wakeup method
-        //sleep_wake_rtc_only(deep_sleep);
-        //sleep_wake_interrupt_only(deep_sleep);
-        sleep_wake_rtc_or_interrupt(deep_sleep);
+    // 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);// use the line below
+    update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack); ///
+    
+    // configure network link checks
+    // network link checks are a good alternative to requiring the gateway to ACK every packet and should allow a single gateway to handle more Dots
+    // check the link every count packets
+    // declare the Dot disconnected after threshold failed link checks
+    // for count = 3 and threshold = 5, the Dot will ask for a link check response every 5 packets and will consider the connection lost if it fails to receive 3 responses in a row
+    update_network_link_check_config(3, 5);
+    
+    // enable or disable Adaptive Data Rate
+    dot->setAdr(adr);
+    
+    // Configure the join delay
+    dot->setJoinDelay(join_delay);
+    
+    // save changes to configuration
+    logInfo("saving configuration");
+    if (!dot->saveConfig()) {
+      logError("failed to save configuration");
     }
- 
-    return 0;
+    
+    // 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();
+  }
+  
+  uint8_t counter = 0;
+  while (true) {
+    std::vector<uint8_t> tx_data;
+    
+    // join network if not joined
+    if (!dot->getNetworkJoinStatus()) {
+      join_network();
+    }
+    
+    tx_data.push_back(++counter);
+    logInfo("sending uplink with data = %d", counter);
+    send_data(tx_data);
+    
+    // if going into deepsleep mode, save the session so we don't need to join again after waking up
+    // not necessary if going into sleep mode since RAM is retained
+    if (deep_sleep) {
+      logInfo("saving network session to NVM");
+      dot->saveNetworkSession();
+    }
+    
+    // ONLY ONE of the three functions below should be uncommented depending on the desired wakeup method
+    //sleep_wake_rtc_only(deep_sleep);
+    //sleep_wake_interrupt_only(deep_sleep);
+    sleep_wake_rtc_or_interrupt(deep_sleep);
+  }
+  
+  return 0;
 }
 
 #endif