Start project of The Things Network workshop with the MultiTech mDot
Dependencies: libmDot mbed-rtos mbed
Fork of mDot_LoRa_Connect_Example_APP_EUI_KEY by
Diff: main.cpp
- Revision:
- 9:d589fb5e68a4
- Parent:
- 8:308a67b71c86
- Child:
- 10:5332d0939ebe
--- a/main.cpp Mon Apr 04 21:26:16 2016 +0000 +++ b/main.cpp Mon Apr 04 22:26:40 2016 +0000 @@ -5,19 +5,40 @@ #include <vector> #include <algorithm> -// these options must match the settings on your Conduit -// uncomment the following lines and edit their values to match your configuration static uint8_t config_app_eui[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; static uint8_t config_app_key[] = { 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x45 }; - static uint8_t config_frequency_sub_band = 7; +mDot* dot; + int main() { + setupNetwork(); + + std::string data_str = "Hello!"; + + // format data for sending to the gateway + std::vector<uint8_t> data; + for (std::string::iterator it = data_str.begin(); it != data_str.end(); it++) + data.push_back((uint8_t) *it); + + while (true) { + // send the data to the gateway + int32_t ret; + if ((ret = dot->send(data)) != mDot::MDOT_OK) { + logError("failed to send", ret, mDot::getReturnCodeString(ret).c_str()); + } else { + logInfo("successfully sent data to gateway"); + } + + osDelay(std::max((uint32_t)5000, (uint32_t)dot->getNextTxMs())); + } + + return 0; +} + +void setupNetwork() { int32_t ret; - mDot* dot; - std::vector<uint8_t> data; - std::string data_str = "hello!"; - + // get a mDot handle dot = mDot::getInstance(); @@ -50,7 +71,7 @@ } if ((ret = dot->setPublicNetwork(true)) != mDot::MDOT_OK) { - logError("failed to set public network"); + logError("failed to enable public network %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); } logInfo("setting app eui"); @@ -72,7 +93,7 @@ // in the 915 (US) frequency band, spreading factors 7 - 10 are available // in the 868 (EU) frequency band, spreading factors 7 - 12 are available logInfo("setting TX spreading factor"); - if ((ret = dot->setTxDataRate(mDot::SF_10)) != mDot::MDOT_OK) { + if ((ret = dot->setTxDataRate(mDot::SF_8)) != mDot::MDOT_OK) { logError("failed to set TX datarate %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); } @@ -87,9 +108,6 @@ if (! dot->saveConfig()) { logError("failed to save configuration"); } - //******************************************* - // end of configuration - //******************************************* // attempt to join the network logInfo("joining network"); @@ -98,22 +116,4 @@ // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again osDelay(std::max((uint32_t)1000, (uint32_t)dot->getNextTxMs())); } - - // format data for sending to the gateway - for (std::string::iterator it = data_str.begin(); it != data_str.end(); it++) - data.push_back((uint8_t) *it); - - while (true) { - // send the data to the gateway - if ((ret = dot->send(data)) != mDot::MDOT_OK) { - logError("failed to send", ret, mDot::getReturnCodeString(ret).c_str()); - } else { - logInfo("successfully sent data to gateway"); - } - - // in the 868 (EU) frequency band, we need to wait until another channel is available before transmitting again - osDelay(std::max((uint32_t)5000, (uint32_t)dot->getNextTxMs())); - } - - return 0; -} +} \ No newline at end of file