Stable version of the xDot library for mbed 5. This version of the library is suitable for deployment scenarios.
Dependents: Dot-Examples XDOT-Devicewise Dot-Examples-delujoc Dot-Examples_receive ... more
Fork of libxDot-dev-mbed5-deprecated by
The Dot library provides a LoRaWan certified stack for LoRa communication using MultiTech mDot and xDot devices. The stack is compatible with mbed 5.
The name of the repository can be used to determine which device the stack was compiled for and if it's a development or production-ready build:
- libmDot-mbed5 -> production-ready build for mDot
- libmDot-dev-mbed5 -> development build for mDot
- libxDot-mbed5 -> production-ready build for xDot
- libxDot-dev-mbed5 -> development build for xDot
A changelog for the Dot library can be found here.
The Dot library version and the version of mbed-os it was compiled against can both be found in the commit message for that revision of the Dot library. Building your application with the same version of mbed-os as what was used to build the Dot library is highly recommended!
The Dot-Examples repository demonstrates how to use the Dot library in a custom application.
The mDot and xDot platform pages have lots of platform specific information and document potential issues, gotchas, etc, and provide instructions for getting started with development. Please take a look at the platform page before starting development as they should answer many questions you will have.
FOTA
Full FOTA support is only available with mDot, xDot does not have the required external flash. xDot can use the FOTA example to dynamically join a multicast session only. After joining the multicast session the received Fragmentation packets could be handed to a host MCU for processing and at completion the firmware can be loaded into the xDot using the bootloader and y-modem. See xDot Developer Guide.
- Add the following code to allow Fota to use the Dot instance
examples/src/fota_example.cpp
// Initialize FOTA singleton Fota::getInstance(dot);
- Add fragmentation handling the the PacketRx event
examples/inc/RadioEvent.h
virtual void PacketRx(uint8_t port, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot, uint8_t retries, uint32_t address, bool dupRx) { mDotEvent::PacketRx(port, payload, size, rssi, snr, ctrl, slot, retries, address, dupRx); #if ACTIVE_EXAMPLE == FOTA_EXAMPLE if(port == 200 || port == 201 || port == 202) { Fota::getInstance()->processCmd(payload, port, size); } #endif }
The FOTA implementation has a few differences from the LoRaWAN Protocol
- Fragmentation Indexing starts at 0
- McKEKey is 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
- Start Time is a count-down in seconds to start of session
Diff: mDotEvent.h
- Revision:
- 14:f0c24ce93427
- Parent:
- 2:4569491293d7
- Child:
- 16:4a382fe8f51b
--- a/mDotEvent.h Thu Jul 27 11:08:40 2017 -0500 +++ b/mDotEvent.h Thu Aug 23 14:21:20 2018 -0500 @@ -1,6 +1,7 @@ #ifndef MDOT_EVENT_H #define MDOT_EVENT_H +#include "mbed.h" #include "mDot.h" #include "MacEvents.h" #include "MTSLog.h" @@ -38,6 +39,7 @@ LoRaMacEventInfoStatus Status; lora::DownlinkControl Ctrl; bool TxAckReceived; + bool DuplicateRx; uint8_t TxNbRetries; uint8_t TxDatarate; uint8_t RxPort; @@ -65,7 +67,9 @@ PongRssi(0), PongSnr(0), AckReceived(false), - TxNbRetries(0) + DuplicateRx(false), + TxNbRetries(0), + _sleep_cb(NULL) { memset(&_flags, 0, sizeof(LoRaMacEventFlags)); memset(&_info, 0, sizeof(LoRaMacEventInfo)); @@ -115,11 +119,20 @@ } } + virtual void TxStart() { + logDebug("mDotEvent - TxStart"); + + // Fire auto sleep cfg event if enabled + if (_sleep_cb) + _sleep_cb(mDot::AUTO_SLEEP_EVT_CFG); + } + virtual void TxDone(uint8_t dr) { RxPayloadSize = 0; LinkCheckAnsReceived = false; PacketReceived = false; AckReceived = false; + DuplicateRx = false; PongReceived = false; TxNbRetries = 0; @@ -131,6 +144,10 @@ _info.TxDatarate = dr; _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; Notify(); + + // If configured, we can sleep until the rx window opens + if (_sleep_cb) + _sleep_cb(mDot::AUTO_SLEEP_EVT_TXDONE); } void Notify() { @@ -152,6 +169,9 @@ _flags.Bits.JoinAccept = 1; _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; Notify(); + + if (_sleep_cb) + _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP); } virtual void JoinFailed(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr) { @@ -161,6 +181,9 @@ _flags.Bits.JoinAccept = 1; _info.Status = LORAMAC_EVENT_INFO_STATUS_JOIN_FAIL; Notify(); + + if (_sleep_cb) + _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP); } virtual void MissedAck(uint8_t retries) { @@ -169,8 +192,8 @@ _info.TxNbRetries = retries; } - virtual void PacketRx(uint8_t port, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot, uint8_t retries = 0) { - logDebug("mDotEvent - PacketRx"); + virtual void PacketRx(uint8_t port, uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot, uint8_t retries, uint32_t address, bool dupRx) { + logDebug("mDotEvent - PacketRx ADDR: %08x", address); RxPort = port; PacketReceived = true; @@ -181,6 +204,8 @@ AckReceived = true; } + DuplicateRx = dupRx; + if (mts::MTSLog::getLogLevel() == mts::MTSLog::TRACE_LEVEL) { std::string packet = mts::Text::bin2hexString(RxPayload, size); logTrace("Payload: %s", packet.c_str()); @@ -196,6 +221,7 @@ _info.RxRssi = rssi; _info.RxSnr = snr; _info.TxAckReceived = AckReceived; + _info.DuplicateRx = DuplicateRx; _info.TxNbRetries = retries; _info.Status = LORAMAC_EVENT_INFO_STATUS_OK; Notify(); @@ -203,6 +229,9 @@ virtual void RxDone(uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr, lora::DownlinkControl ctrl, uint8_t slot) { logDebug("mDotEvent - RxDone"); + + if (_sleep_cb) + _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP); } virtual void Pong(int16_t m_rssi, int8_t m_snr, int16_t s_rssi, int8_t s_snr) { @@ -229,12 +258,20 @@ } virtual void RxTimeout(uint8_t slot) { - // logDebug("mDotEvent - RxTimeout"); + logDebug("mDotEvent - RxTimeout on Slot %d", slot); _flags.Bits.Tx = 0; _flags.Bits.RxSlot = slot; _info.Status = LORAMAC_EVENT_INFO_STATUS_RX_TIMEOUT; Notify(); + + if (_sleep_cb) { + // If this is the first rx window we can sleep until the next one + if (slot == 1) + _sleep_cb(mDot::AUTO_SLEEP_EVT_RX1_TIMEOUT); + else + _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP); + } } virtual void RxError(uint8_t slot) { @@ -246,12 +283,23 @@ _flags.Bits.RxSlot = slot; _info.Status = LORAMAC_EVENT_INFO_STATUS_RX_ERROR; Notify(); + + if (_sleep_cb) + _sleep_cb(mDot::AUTO_SLEEP_EVT_CLEANUP); } virtual uint8_t MeasureBattery(void) { return 255; } + void AttachSleepCallback(Callback<void(mDot::AutoSleepEvent_t)> cb) { + _sleep_cb = cb; + } + + void DetachSleepCallback() { + _sleep_cb = NULL; + } + bool LinkCheckAnsReceived; uint8_t DemodMargin; uint8_t NbGateways; @@ -266,6 +314,7 @@ int16_t PongSnr; bool AckReceived; + bool DuplicateRx; uint8_t TxNbRetries; LoRaMacEventFlags& Flags() { @@ -276,6 +325,8 @@ } private: + /* Hook to inject a sleep method in between receive windows */ + Callback<void(mDot::AutoSleepEvent_t)> _sleep_cb; LoRaMacEventFlags _flags; LoRaMacEventInfo _info;