Two way data over LoRaWAN using Multitech mDot
This is example firmware for the Multitech mDot. It demonstrates how to:
- Do two-way data.
- Sleep aggressively and only wake up when the wake-up pin is triggered.
- Handle errors, retries and duty cycle errors.
- Cache data in non-volatile storage.
Based on mbed OS 5.1, hard faults against mbed OS 5.3 unfortunately. Can be compiled with GCC and ARMCC (but not IAR).
To do a new transmission, short pin D6 / PA_1.
Diff: main.cpp
- Revision:
- 4:0fd5e5e121ea
- Parent:
- 3:ac5101a47080
--- a/main.cpp Tue Jan 03 17:25:01 2017 +0000 +++ b/main.cpp Wed Jan 04 13:45:49 2017 +0000 @@ -57,6 +57,18 @@ static bool send_data(void) { int32_t ret; + // check join state, @todo: add a timeout here, join is very expensive on the battery... + if (!dot->getNetworkJoinStatus()) { + logInfo("trying to send before joining, retry join..."); + if ((ret = dot->joinNetwork()) != mDot::MDOT_OK ) { + logError("failed to join network %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); + return false; + } + else { + logInfo("joined network successfully"); + } + } + std::vector<uint8_t> data; data.push_back(counter >> 8 & 0xff); data.push_back(counter & 0xff); @@ -205,9 +217,10 @@ logInfo("joining network"); if ((ret = dot->joinNetwork()) != mDot::MDOT_OK ) { logError("failed to join network %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); - return false; } - logInfo("joined network successfully"); + else { + logInfo("joined network successfully"); + } //******************************************* // end of configuration