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: parse_keys.h
- Revision:
- 0:20fbd6f66b11
- Child:
- 2:ff17ce021cfb
diff -r 000000000000 -r 20fbd6f66b11 parse_keys.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/parse_keys.h Tue Jan 03 13:20:36 2017 +0000 @@ -0,0 +1,57 @@ +#ifndef DISPENSER_PARSE_KEYS_H +#define DISPENSER_PARSE_KEYS_H + +#include "mDot.h" + +class ParseKeys { +public: + static bool initialize(mDot* dot, const char* aDevAddr, const char* aNwkSKey, const char* aAppSKey) { + int32_t ret; + + // parse devkey + std::vector<uint8_t> loriot_nwk_skey(16); + for (uint8_t ni = 0; ni < 16; ni++) + { + const char hex[] = { '0', 'x', aNwkSKey[ni * 2], aNwkSKey[ni * 2 + 1], '\0' }; + loriot_nwk_skey[ni] = strtoul(hex, NULL, 16); + } + + // parse appkey + std::vector<uint8_t> loriot_app_skey(16); + for (uint8_t ai = 0; ai < 16; ai++) + { + const char hex[] = { '0', 'x', aAppSKey[ai * 2], aAppSKey[ai * 2 + 1], '\0' }; + loriot_app_skey[ai] = strtoul(hex, NULL, 16); + } + + // parse dev addr + std::vector<uint8_t> loriot_dev_addr(4); + for (uint8_t ai = 0; ai < 4; ai++) + { + const char hex[] = { '0', 'x', aDevAddr[ai * 2], aDevAddr[ai * 2 + 1], '\0' }; + loriot_dev_addr[ai] = strtoul(hex, NULL, 16); + } + + logInfo("setting network address"); + if ((ret = dot->setNetworkAddress(loriot_dev_addr)) != mDot::MDOT_OK) { + logError("failed to set network address %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); + return false; + } + + logInfo("setting network session key"); + if ((ret = dot->setNetworkSessionKey(loriot_nwk_skey)) != mDot::MDOT_OK) { + logError("failed to set network session key %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); + return false; + } + + logInfo("setting app session key"); + if ((ret = dot->setDataSessionKey(loriot_app_skey)) != mDot::MDOT_OK) { + logError("failed to set app session key %d:%s", ret, mDot::getReturnCodeString(ret).c_str()); + return false; + } + + return true; + } +}; + +#endif // DISPENSER_PARSE_KEYS_H