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.
Revision 4:0fd5e5e121ea, committed 2017-01-04
- Comitter:
- Jan Jongboom
- Date:
- Wed Jan 04 13:45:49 2017 +0000
- Parent:
- 3:ac5101a47080
- Commit message:
- Retry OTA join when fails during startup
Changed in this revision
README.md | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/README.md Tue Jan 03 17:25:01 2017 +0000 +++ b/README.md Wed Jan 04 13:45:49 2017 +0000 @@ -1,6 +1,6 @@ # Two way data using Multitech mDot -Only builds with ARMCC, not with GCC. Demonstrates two-way data over LoRaWAN using Multitech mDot. +Demonstrates two-way data over LoRaWAN using Multitech mDot. 1. Triggers transmission when D6 goes high - this is the special wake-up pin on the mDot. Short D6 to test quickly. 2. The RX window is used to toggle D2. If 0x00 is received the pin goes high, if 0x01 is received the pin goes low (as the LEDs are inverted on the break-out board).
--- 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