Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: libxDot-mbed5 TSL2561
Fork of Dot-Examples by
class_c_example.cpp
00001 #include "dot_util.h" 00002 #include "RadioEvent.h" 00003 00004 #if ACTIVE_EXAMPLE == CLASS_C_EXAMPLE 00005 00006 ///////////////////////////////////////////////////////////////////////////// 00007 // -------------------- DOT LIBRARY REQUIRED ------------------------------// 00008 // * Because these example programs can be used for both mDot and xDot // 00009 // devices, the LoRa stack is not included. The libmDot library should // 00010 // be imported if building for mDot devices. The libxDot library // 00011 // should be imported if building for xDot devices. // 00012 // * https://developer.mbed.org/teams/MultiTech/code/libmDot-dev-mbed5/ // 00013 // * https://developer.mbed.org/teams/MultiTech/code/libmDot-mbed5/ // 00014 // * https://developer.mbed.org/teams/MultiTech/code/libxDot-dev-mbed5/ // 00015 // * https://developer.mbed.org/teams/MultiTech/code/libxDot-mbed5/ // 00016 ///////////////////////////////////////////////////////////////////////////// 00017 00018 ///////////////////////////////////////////////////////////// 00019 // * these options must match the settings on your gateway // 00020 // * edit their values to match your configuration // 00021 // * frequency sub band is only relevant for the 915 bands // 00022 // * either the network name and passphrase can be used or // 00023 // the network ID (8 bytes) and KEY (16 bytes) // 00024 ///////////////////////////////////////////////////////////// 00025 static std::string network_name = "MultiTech"; 00026 static std::string network_passphrase = "MultiTech"; 00027 static uint8_t network_id[] = { 0x6C, 0x4E, 0xEF, 0x66, 0xF4, 0x79, 0x86, 0xA6 }; 00028 static uint8_t network_key[] = { 0x1F, 0x33, 0xA1, 0x70, 0xA5, 0xF1, 0xFD, 0xA0, 0xAB, 0x69, 0x7A, 0xAE, 0x2B, 0x95, 0x91, 0x6B }; 00029 static uint8_t frequency_sub_band = 0; 00030 static lora::NetworkType public_network = lora::PUBLIC_LORAWAN; 00031 static uint8_t join_delay = 5; 00032 static uint8_t ack = 1; 00033 static bool adr = true; 00034 00035 mDot* dot = NULL; 00036 lora::ChannelPlan* plan = NULL; 00037 00038 Serial pc(USBTX, USBRX); 00039 00040 int main() { 00041 // Custom event handler for automatically displaying RX data 00042 RadioEvent events; 00043 00044 pc.baud(115200); 00045 00046 mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); 00047 00048 #if CHANNEL_PLAN == CP_US915 00049 plan = new lora::ChannelPlan_US915(); 00050 #elif CHANNEL_PLAN == CP_AU915 00051 plan = new lora::ChannelPlan_AU915(); 00052 #elif CHANNEL_PLAN == CP_EU868 00053 plan = new lora::ChannelPlan_EU868(); 00054 #elif CHANNEL_PLAN == CP_KR920 00055 plan = new lora::ChannelPlan_KR920(); 00056 #elif CHANNEL_PLAN == CP_AS923 00057 plan = new lora::ChannelPlan_AS923(); 00058 #elif CHANNEL_PLAN == CP_AS923_JAPAN 00059 plan = new lora::ChannelPlan_AS923_Japan(); 00060 #elif CHANNEL_PLAN == CP_IN865 00061 plan = new lora::ChannelPlan_IN865(); 00062 #endif 00063 assert(plan); 00064 00065 dot = mDot::getInstance(plan); 00066 assert(dot); 00067 00068 logInfo("mbed-os library version: %d", MBED_LIBRARY_VERSION); 00069 00070 // start from a well-known state 00071 logInfo("defaulting Dot configuration"); 00072 dot->resetConfig(); 00073 dot->resetNetworkSession(); 00074 00075 // make sure library logging is turned on 00076 dot->setLogLevel(mts::MTSLog::INFO_LEVEL); 00077 00078 // attach the custom events handler 00079 dot->setEvents(&events); 00080 00081 // update configuration if necessary 00082 if (dot->getJoinMode() != mDot::OTA) { 00083 logInfo("changing network join mode to OTA"); 00084 if (dot->setJoinMode(mDot::OTA) != mDot::MDOT_OK) { 00085 logError("failed to set network join mode to OTA"); 00086 } 00087 } 00088 // 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 00089 // only one method or the other should be used! 00090 // network ID = crc64(network name) 00091 // network KEY = cmac(network passphrase) 00092 update_ota_config_name_phrase(network_name, network_passphrase, frequency_sub_band, public_network, ack); 00093 //update_ota_config_id_key(network_id, network_key, frequency_sub_band, public_network, ack); 00094 00095 // configure the Dot for class C operation 00096 // the Dot must also be configured on the gateway for class C 00097 // use the lora-query application to do this on a Conduit: http://www.multitech.net/developer/software/lora/lora-network-server/ 00098 // to provision your Dot for class C operation with a 3rd party gateway, see the gateway or network provider documentation 00099 logInfo("changing network mode to class C"); 00100 if (dot->setClass("C") != mDot::MDOT_OK) { 00101 logError("failed to set network mode to class C"); 00102 } 00103 00104 // enable or disable Adaptive Data Rate 00105 dot->setAdr(adr); 00106 00107 // Configure the join delay 00108 dot->setJoinDelay(join_delay); 00109 00110 // save changes to configuration 00111 logInfo("saving configuration"); 00112 if (!dot->saveConfig()) { 00113 logError("failed to save configuration"); 00114 } 00115 00116 // display configuration 00117 display_config(); 00118 00119 uint8_t counter = 0; 00120 while (true) { 00121 std::vector<uint8_t> tx_data; 00122 00123 // join network if not joined 00124 if (!dot->getNetworkJoinStatus()) { 00125 join_network(); 00126 } 00127 00128 tx_data.push_back(++counter); 00129 logInfo("sending uplink with data = %d", counter); 00130 send_data(tx_data); 00131 00132 // the Dot can't sleep in class C mode 00133 // it must be waiting for data from the gateway 00134 // send data every 30s 00135 logInfo("waiting for 30s"); 00136 wait(30); 00137 } 00138 00139 return 0; 00140 } 00141 00142 #endif 00143
Generated on Tue Jul 12 2022 18:10:22 by
