Revision 6:febbdd0d0e55, committed 2018-09-17
- Comitter:
- Lucian Corduneanu
- Date:
- Mon Sep 17 12:47:16 2018 +0300
- Parent:
- 5:9eedfec35eed
- Commit message:
- IEM-423 Add OTA and data rate support from config.h
Changed in this revision
diff -r 9eedfec35eed -r febbdd0d0e55 MultitechDot.cpp
--- a/MultitechDot.cpp Sun Jul 22 12:42:09 2018 +0300
+++ b/MultitechDot.cpp Mon Sep 17 12:47:16 2018 +0300
@@ -6,6 +6,9 @@
using namespace lora;
ChannelPlan *plan = new ChannelPlan_EU868();
+ plan->SetNumberOfChannels(1);
+ plan->SetTxChannel(0);
+
MultitechDot *dot = (MultitechDot *) mDot::getInstance(plan);
dot->config(config);
@@ -17,9 +20,20 @@
_config = config;
this->setLogLevel(config->log_level);
- this->setDisableDutyCycle(config->disable_duty_cycle);
- logInfo("Start configuring the device");
+ if(config->join_mode == mDot::MANUAL) {
+ _manual_config();
+ } else if (config->join_mode == mDot::OTA) {
+ _ota_config();
+ }
+}
+
+struct dot_config *MultitechDot::get_config() {
+ return _config;
+}
+
+void MultitechDot::_manual_config() {
+ logInfo("MANUAL config");
if (!this->getStandbyFlag()) {
logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION);
@@ -28,6 +42,9 @@
this->resetConfig();
this->resetNetworkSession();
+ this->setDisableDutyCycle(_config->disable_duty_cycle);
+ this->setTxDataRate(_config->data_rate);
+
// update configuration if necessary
if (this->getJoinMode() != this->MANUAL) {
logInfo("changing network join mode to MANUAL");
@@ -46,10 +63,20 @@
// 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
- this->update_manual_config(config);
+ BaseDot::update_manual_config(
+ _config->network_address,
+ _config->network_session_key,
+ _config->data_session_key,
+ _config->frequency_sub_band,
+ _config->public_network,
+ _config->ack
+ );
// enable or disable Adaptive Data Rate
- this->setAdr(config->adr);
+ this->setAdr(_config->adr);
+
+ // Configure the join delay
+ this->setJoinDelay(_config->join_delay);
// save changes to configuration
logInfo("saving configuration");
@@ -67,20 +94,70 @@
}
}
-struct dot_config *MultitechDot::get_config() {
- return _config;
-}
+
+void MultitechDot::_ota_config() {
+ logInfo("OTA config");
+ if (!this->getStandbyFlag()) {
+ logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION);
+ // start from a well-known state
+ logInfo("defaulting Dot configuration");
+ this->resetConfig();
+ this->resetNetworkSession();
+
+ this->setDisableDutyCycle(_config->disable_duty_cycle);
+ this->setTxDataRate(_config->data_rate);
+
+ // make sure library logging is turned on
+ this->setLogLevel(mts::MTSLog::INFO_LEVEL);
-void MultitechDot::update_manual_config(struct dot_config *config) {
- BaseDot::update_manual_config(
- config->network_address,
- config->network_session_key,
- config->data_session_key,
- config->frequency_sub_band,
- config->public_network,
- config->ack
- );
+ // update configuration if necessary
+ if (this->getJoinMode() != mDot::OTA) {
+ logInfo("changing network join mode to OTA");
+ if (this->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)
+ BaseDot::update_ota_config_id_key(
+ _config->network_id,
+ _config->network_key,
+ _config->frequency_sub_band,
+ _config->public_network,
+ _config->ack
+ );
+ //update_ota_config_id_key(network_id, network_key, frequency_sub_band, network_type, 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
+ this->setAdr(_config->adr);
+
+ // Configure the join delay
+ this->setJoinDelay(_config->join_delay);
+
+ // save changes to configuration
+ logInfo("saving configuration");
+ if (!this->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");
+ this->restoreNetworkSession();
+ }
}
void MultitechDot::sleep_wake_rtc_or_interrupt(uint32_t delay_s, bool deepsleep) {
diff -r 9eedfec35eed -r febbdd0d0e55 MultitechDot.h
--- a/MultitechDot.h Sun Jul 22 12:42:09 2018 +0300
+++ b/MultitechDot.h Mon Sep 17 12:47:16 2018 +0300
@@ -12,14 +12,16 @@
struct dot_config *get_config();
- void update_manual_config(struct dot_config *config);
-
void sleep_wake_rtc_or_interrupt(uint32_t delay_s, bool deepsleep);
void sleep_reset_hsi();
protected:
struct dot_config *_config;
+
+ void _manual_config();
+
+ void _ota_config();
};
diff -r 9eedfec35eed -r febbdd0d0e55 dot_defs.h
--- a/dot_defs.h Sun Jul 22 12:42:09 2018 +0300
+++ b/dot_defs.h Mon Sep 17 12:47:16 2018 +0300
@@ -1,24 +1,42 @@
#ifndef MBED_MULTITECHDOT_DOT_DEFS_H
#define MBED_MULTITECHDOT_DOT_DEFS_H
+#include "mDot.h"
#include "MTSLog.h"
struct dot_config {
/**
- * DevAddr, 4 bytes.
+ * Join Mode
+ */
+ mDot::JoinMode join_mode;
+
+ /**
+ * DevAddr, 4 bytes, for MANUAL (ABP) join mode.
*/
uint8_t network_address[4];
/**
- * NwkSKey, 16 bytes
+ * NwkSKey, 16 bytes, for MANUAL (ABP) join mode.
*/
uint8_t network_session_key[16];
/**
- * AppSKey, 16 bytes
+ * AppSKey, 16 bytes, for MANUAL (ABP) join mode.
*/
uint8_t data_session_key[16];
+ /**
+ * AppEUI or Network ID, 16 bytes, for OTA join mode.
+ */
+ uint8_t network_id[16];
+
+ /**
+ * AppKey or Network Key, 16 bytes, for OTA join mode.
+ */
+ uint8_t network_key[16];
+
+ uint8_t join_delay;
+
uint8_t frequency_sub_band;
bool public_network;
@@ -28,6 +46,8 @@
*/
uint8_t ack;
+ mDot::DataRates data_rate;
+
/**
* Enable Adaptive Data Rate
*/