
FF1705 support added
Dependencies: libxDot-dev-mbed5-deprecated ISL29011
Fork of Dot-Examples by
Dot-Examples rev. 31:7ec180e84cb6 have been tested with xdot-library 3.0.0-19-gb6c0ba2 and mbed-os-5.6.2
Revision 21:09d05faf0e13, committed 2017-06-09
- Comitter:
- Mike Fiore
- Date:
- Fri Jun 09 08:31:21 2017 -0500
- Parent:
- 20:9ea0f3385ab3
- Child:
- 22:d9bc10bbc433
- Commit message:
- update Dot-Examples to support Dot 3.x.x releases - new channel plans, LBT, & external channel plan functionality. Also a few bug fixes.
Changed in this revision
--- a/examples/example_config.h Tue May 16 10:47:10 2017 -0500 +++ b/examples/example_config.h Fri Jun 09 08:31:21 2017 -0500 @@ -8,6 +8,20 @@ #define CLASS_C_EXAMPLE 5 // see class_c_example.cpp // the active example is the one that will be compiled +#if !defined(ACTIVE_EXAMPLE) #define ACTIVE_EXAMPLE OTA_EXAMPLE +#endif -#endif \ No newline at end of file +// the active channel plan is the one that will be compiled +// options are : +// CP_US915 +// CP_AU915 +// CP_EU868 +// CP_KR920 +// CP_AS923 +// CP_AS923_JAPAN +#if !defined(CHANNEL_PLAN) +#define CHANNEL_PLAN CP_US915 +#endif + +#endif
--- a/examples/inc/RadioEvent.h Tue May 16 10:47:10 2017 -0500 +++ b/examples/inc/RadioEvent.h Fri Jun 09 08:31:21 2017 -0500 @@ -63,12 +63,9 @@ logDebug("Rx %d bytes", info->RxBufferSize); if (info->RxBufferSize > 0) { - // print RX data as hexadecimal - //printf("Rx data: %s\r\n", mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str()); - - // print RX data as string + // print RX data as string and hexadecimal std::string rx((const char*)info->RxBuffer, info->RxBufferSize); - printf("Rx data: %s\r\n", rx.c_str()); + printf("Rx data: %s [%s]\r\n", rx.c_str(), mts::Text::bin2hexString(info->RxBuffer, info->RxBufferSize).c_str()); } } }
--- a/examples/inc/dot_util.h Tue May 16 10:47:10 2017 -0500 +++ b/examples/inc/dot_util.h Fri Jun 09 08:31:21 2017 -0500 @@ -3,6 +3,7 @@ #include "mbed.h" #include "mDot.h" +#include "ChannelPlans.h" #include "MTSLog.h" #include "MTSText.h" #include "ISL29011.h"
--- a/examples/src/auto_ota_example.cpp Tue May 16 10:47:10 2017 -0500 +++ b/examples/src/auto_ota_example.cpp Fri Jun 09 08:31:21 2017 -0500 @@ -29,6 +29,7 @@ static uint8_t frequency_sub_band = 0; static bool public_network = false; static uint8_t ack = 0; +static bool adr = true; // deepsleep consumes slightly less current than sleep // in sleep mode, IO state is maintained, RAM is retained, and application will resume after waking up @@ -37,6 +38,7 @@ static bool deep_sleep = true; mDot* dot = NULL; +lora::ChannelPlan* plan = NULL; Serial pc(USBTX, USBRX); @@ -55,7 +57,23 @@ mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); - dot = mDot::getInstance(); +#if CHANNEL_PLAN == CP_US915 + plan = new lora::ChannelPlan_US915(); +#elif CHANNEL_PLAN == CP_AU915 + plan = new lora::ChannelPlan_AU915(); +#elif CHANNEL_PLAN == CP_EU868 + plan = new lora::ChannelPlan_EU868(); +#elif CHANNEL_PLAN == CP_KR920 + plan = new lora::ChannelPlan_KR920(); +#elif CHANNEL_PLAN == CP_AS923 + plan = new lora::ChannelPlan_AS923(); +#elif CHANNEL_PLAN == CP_AS923_JAPAN + plan = new lora::ChannelPlan_AS923_Japan(); +#endif + assert(plan); + + dot = mDot::getInstance(plan); + assert(dot); // attach the custom events handler dot->setEvents(&events); @@ -90,9 +108,12 @@ // 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 be considered disconnected after 15 missed packets in a row + // 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); + // save changes to configuration logInfo("saving configuration"); if (!dot->saveConfig()) {
--- a/examples/src/class_c_example.cpp Tue May 16 10:47:10 2017 -0500 +++ b/examples/src/class_c_example.cpp Fri Jun 09 08:31:21 2017 -0500 @@ -29,8 +29,10 @@ static uint8_t frequency_sub_band = 0; static bool public_network = false; static uint8_t ack = 1; +static bool adr = true; mDot* dot = NULL; +lora::ChannelPlan* plan = NULL; Serial pc(USBTX, USBRX); @@ -49,7 +51,23 @@ mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); - dot = mDot::getInstance(); +#if CHANNEL_PLAN == CP_US915 + plan = new lora::ChannelPlan_US915(); +#elif CHANNEL_PLAN == CP_AU915 + plan = new lora::ChannelPlan_AU915(); +#elif CHANNEL_PLAN == CP_EU868 + plan = new lora::ChannelPlan_EU868(); +#elif CHANNEL_PLAN == CP_KR920 + plan = new lora::ChannelPlan_KR920(); +#elif CHANNEL_PLAN == CP_AS923 + plan = new lora::ChannelPlan_AS923(); +#elif CHANNEL_PLAN == CP_AS923_JAPAN + plan = new lora::ChannelPlan_AS923_Japan(); +#endif + assert(plan); + + dot = mDot::getInstance(plan); + assert(dot); logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION); @@ -86,6 +104,9 @@ if (dot->setClass("C") != mDot::MDOT_OK) { logError("failed to set network mode to class C"); } + + // enable or disable Adaptive Data Rate + dot->setAdr(adr); // save changes to configuration logInfo("saving configuration");
--- a/examples/src/dot_util.cpp Tue May 16 10:47:10 2017 -0500 +++ b/examples/src/dot_util.cpp Fri Jun 09 08:31:21 2017 -0500 @@ -19,8 +19,9 @@ logInfo("====================="); logInfo("version ------------------ %s", dot->getId().c_str()); logInfo("device ID/EUI ------------ %s", mts::Text::bin2hexString(dot->getDeviceId()).c_str()); - logInfo("frequency band ----------- %s", mDot::FrequencyBandStr(dot->getFrequencyBand()).c_str()); - if (dot->getFrequencySubBand() != mDot::FB_EU868) { + logInfo("default channel plan ----- %s", mDot::FrequencyBandStr(dot->getDefaultFrequencyBand()).c_str()); + logInfo("current channel plan ----- %s", mDot::FrequencyBandStr(dot->getFrequencyBand()).c_str()); + if (lora::ChannelPlan::IsPlanFixed(dot->getFrequencyBand())) { logInfo("frequency sub band ------- %u", dot->getFrequencySubBand()); } logInfo("public network ----------- %s", dot->getPublicNetwork() ? "on" : "off"); @@ -49,7 +50,12 @@ } logInfo("TX datarate -------------- %s", mDot::DataRateStr(dot->getTxDataRate()).c_str()); logInfo("TX power ----------------- %lu dBm", dot->getTxPower()); - logInfo("atnenna gain ------------- %u dBm", dot->getAntennaGain()); + logInfo("antenna gain ------------- %u dBm", dot->getAntennaGain()); + logInfo("LBT ---------------------- %s", dot->getLbtTimeUs() ? "on" : "off"); + if (dot->getLbtTimeUs()) { + logInfo("LBT time ----------------- %lu us", dot->getLbtTimeUs()); + logInfo("LBT threshold ------------ %d dBm", dot->getLbtThreshold()); + } } void update_ota_config_name_phrase(std::string network_name, std::string network_passphrase, uint8_t frequency_sub_band, bool public_network, uint8_t ack) { @@ -73,11 +79,13 @@ } } - if (current_frequency_sub_band != frequency_sub_band) { - logInfo("changing frequency sub band from %u to %u", current_frequency_sub_band, frequency_sub_band); - if (dot->setFrequencySubBand(frequency_sub_band) != mDot::MDOT_OK) { - logError("failed to set frequency sub band to %u", frequency_sub_band); - } + if (lora::ChannelPlan::IsPlanFixed(dot->getFrequencyBand())) { + if (current_frequency_sub_band != frequency_sub_band) { + logInfo("changing frequency sub band from %u to %u", current_frequency_sub_band, frequency_sub_band); + if (dot->setFrequencySubBand(frequency_sub_band) != mDot::MDOT_OK) { + logError("failed to set frequency sub band to %u", frequency_sub_band); + } + } } if (current_public_network != public_network) { @@ -119,11 +127,13 @@ } } - if (current_frequency_sub_band != frequency_sub_band) { - logInfo("changing frequency sub band from %u to %u", current_frequency_sub_band, frequency_sub_band); - if (dot->setFrequencySubBand(frequency_sub_band) != mDot::MDOT_OK) { - logError("failed to set frequency sub band to %u", frequency_sub_band); - } + if (lora::ChannelPlan::IsPlanFixed(dot->getFrequencyBand())) { + if (current_frequency_sub_band != frequency_sub_band) { + logInfo("changing frequency sub band from %u to %u", current_frequency_sub_band, frequency_sub_band); + if (dot->setFrequencySubBand(frequency_sub_band) != mDot::MDOT_OK) { + logError("failed to set frequency sub band to %u", frequency_sub_band); + } + } } if (current_public_network != public_network) {
--- a/examples/src/manual_example.cpp Tue May 16 10:47:10 2017 -0500 +++ b/examples/src/manual_example.cpp Fri Jun 09 08:31:21 2017 -0500 @@ -26,6 +26,7 @@ static uint8_t frequency_sub_band = 6; static bool public_network = false; static uint8_t ack = 1; +static bool adr = true; // deepsleep consumes slightly less current than sleep // in sleep mode, IO state is maintained, RAM is retained, and application will resume after waking up @@ -34,6 +35,7 @@ static bool deep_sleep = true; mDot* dot = NULL; +lora::ChannelPlan* plan = NULL; Serial pc(USBTX, USBRX); @@ -52,7 +54,23 @@ mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); - dot = mDot::getInstance(); +#if CHANNEL_PLAN == CP_US915 + plan = new lora::ChannelPlan_US915(); +#elif CHANNEL_PLAN == CP_AU915 + plan = new lora::ChannelPlan_AU915(); +#elif CHANNEL_PLAN == CP_EU868 + plan = new lora::ChannelPlan_EU868(); +#elif CHANNEL_PLAN == CP_KR920 + plan = new lora::ChannelPlan_KR920(); +#elif CHANNEL_PLAN == CP_AS923 + plan = new lora::ChannelPlan_AS923(); +#elif CHANNEL_PLAN == CP_AS923_JAPAN + plan = new lora::ChannelPlan_AS923_Japan(); +#endif + assert(plan); + + dot = mDot::getInstance(plan); + assert(dot); // attach the custom events handler dot->setEvents(&events); @@ -88,6 +106,9 @@ // 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); + // enable or disable Adaptive Data Rate + dot->setAdr(adr); + // save changes to configuration logInfo("saving configuration"); if (!dot->saveConfig()) {
--- a/examples/src/ota_example.cpp Tue May 16 10:47:10 2017 -0500 +++ b/examples/src/ota_example.cpp Fri Jun 09 08:31:21 2017 -0500 @@ -29,6 +29,7 @@ static uint8_t frequency_sub_band = 0; static bool public_network = false; static uint8_t ack = 0; +static bool adr = true; // deepsleep consumes slightly less current than sleep // in sleep mode, IO state is maintained, RAM is retained, and application will resume after waking up @@ -37,6 +38,7 @@ static bool deep_sleep = false; mDot* dot = NULL; +lora::ChannelPlan* plan = NULL; Serial pc(USBTX, USBRX); @@ -55,7 +57,23 @@ mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); - dot = mDot::getInstance(); +#if CHANNEL_PLAN == CP_US915 + plan = new lora::ChannelPlan_US915(); +#elif CHANNEL_PLAN == CP_AU915 + plan = new lora::ChannelPlan_AU915(); +#elif CHANNEL_PLAN == CP_EU868 + plan = new lora::ChannelPlan_EU868(); +#elif CHANNEL_PLAN == CP_KR920 + plan = new lora::ChannelPlan_KR920(); +#elif CHANNEL_PLAN == CP_AS923 + plan = new lora::ChannelPlan_AS923(); +#elif CHANNEL_PLAN == CP_AS923_JAPAN + plan = new lora::ChannelPlan_AS923_Japan(); +#endif + assert(plan); + + dot = mDot::getInstance(plan); + assert(dot); // attach the custom events handler dot->setEvents(&events); @@ -89,8 +107,11 @@ // 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 be considered disconnected after 15 missed packets in a row + // 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); // save changes to configuration logInfo("saving configuration");
--- a/examples/src/peer_to_peer_example.cpp Tue May 16 10:47:10 2017 -0500 +++ b/examples/src/peer_to_peer_example.cpp Fri Jun 09 08:31:21 2017 -0500 @@ -24,6 +24,7 @@ static uint8_t data_session_key[] = { 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04, 0x01, 0x02, 0x03, 0x04 }; mDot* dot = NULL; +lora::ChannelPlan* plan = NULL; Serial pc(USBTX, USBRX); @@ -46,7 +47,23 @@ mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); - dot = mDot::getInstance(); +#if CHANNEL_PLAN == CP_US915 + plan = new lora::ChannelPlan_US915(); +#elif CHANNEL_PLAN == CP_AU915 + plan = new lora::ChannelPlan_AU915(); +#elif CHANNEL_PLAN == CP_EU868 + plan = new lora::ChannelPlan_EU868(); +#elif CHANNEL_PLAN == CP_KR920 + plan = new lora::ChannelPlan_KR920(); +#elif CHANNEL_PLAN == CP_AS923 + plan = new lora::ChannelPlan_AS923(); +#elif CHANNEL_PLAN == CP_AS923_JAPAN + plan = new lora::ChannelPlan_AS923_Japan(); +#endif + assert(plan); + + dot = mDot::getInstance(plan); + assert(dot); logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION); @@ -69,31 +86,58 @@ } frequency_band = dot->getFrequencyBand(); switch (frequency_band) { - case mDot::FB_EU868: + case lora::ChannelPlan::EU868_OLD: + case lora::ChannelPlan::EU868: // 250kHz channels achieve higher throughput - // DR6 : SF7 @ 250kHz - // DR0 - DR5 (125kHz channels) available but much slower + // DR_6 : SF7 @ 250kHz + // DR_0 - DR_5 (125kHz channels) available but much slower tx_frequency = 869850000; - tx_datarate = mDot::DR6; + tx_datarate = lora::DR_6; // the 869850000 frequency is 100% duty cycle if the total power is under 7 dBm - tx power 4 + antenna gain 3 = 7 tx_power = 4; break; - case mDot::FB_US915: - case mDot::FB_AU915: - default: + + case lora::ChannelPlan::US915_OLD: + case lora::ChannelPlan::US915: + case lora::ChannelPlan::AU915_OLD: + case lora::ChannelPlan::AU915: // 500kHz channels achieve highest throughput - // DR8 : SF12 @ 500kHz - // DR9 : SF11 @ 500kHz - // DR10 : SF10 @ 500kHz - // DR11 : SF9 @ 500kHz - // DR12 : SF8 @ 500kHz - // DR13 : SF7 @ 500kHz - // DR0 - DR3 (125kHz channels) available but much slower + // DR_8 : SF12 @ 500kHz + // DR_9 : SF11 @ 500kHz + // DR_10 : SF10 @ 500kHz + // DR_11 : SF9 @ 500kHz + // DR_12 : SF8 @ 500kHz + // DR_13 : SF7 @ 500kHz + // DR_0 - DR_3 (125kHz channels) available but much slower tx_frequency = 915500000; - tx_datarate = mDot::DR13; + tx_datarate = lora::DR_13; // 915 bands have no duty cycle restrictions, set tx power to max tx_power = 20; break; + + case lora::ChannelPlan::AS923: + case lora::ChannelPlan::AS923_JAPAN: + // 250kHz channels achieve higher throughput + // DR_6 : SF7 @ 250kHz + // DR_0 - DR_5 (125kHz channels) available but much slower + tx_frequency = 924800000; + tx_datarate = lora::DR_6; + tx_power = 16; + break; + + case lora::ChannelPlan::KR920: + // DR_5 : SF7 @ 125kHz + tx_frequency = 922700000; + tx_datarate = lora::DR_5; + tx_power = 14; + break; + + default: + while (true) { + logFatal("no known channel plan in use - extra configuration is needed!"); + wait(5); + } + break; } // in PEER_TO_PEER mode there is no join request/response transaction // as long as both Dots are configured correctly, they should be able to communicate