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 MultiTech

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:

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
Revision:
14:f0c24ce93427
Parent:
10:1e831990a669
Child:
16:4a382fe8f51b
--- a/mDot.h	Thu Jul 27 11:08:40 2017 -0500
+++ b/mDot.h	Thu Aug 23 14:21:20 2018 -0500
@@ -51,8 +51,6 @@
         uint32_t RTC_ReadBackupRegister(uint32_t RTC_BKP_DR);
         void RTC_WriteBackupRegister(uint32_t RTC_BKP_DR, uint32_t Data);
 
-        void wakeup();
-
         void enterStopMode(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM);
         void enterStandbyMode(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM);
 
@@ -111,6 +109,7 @@
             MDOT_AGGREGATED_DUTY_CYCLE = -11,
             MDOT_MAX_PAYLOAD_EXCEEDED = -12,
             MDOT_LBT_CHANNEL_BUSY = -13,
+            MDOT_NOT_IDLE = -14,
             MDOT_ERROR = -1024,
         } mdot_ret_code;
 
@@ -147,15 +146,7 @@
             DR12,
             DR13,
             DR14,
-            DR15,
-            SF_12 = 16,
-            SF_11,
-            SF_10,
-            SF_9,
-            SF_8,
-            SF_7,
-            SF_7H,
-            SF_FSK
+            DR15
         };
 
         enum FrequencySubBands {
@@ -241,7 +232,7 @@
 
         typedef struct {
                 bool status;
-                int32_t dBm;
+                uint8_t dBm;
                 uint32_t gateways;
                 std::vector<uint8_t> payload;
         } link_check;
@@ -252,9 +243,6 @@
                 int16_t snr;
         } ping_response;
 
-        static const uint8_t MaxLengths_915[];
-        static const uint8_t MaxLengths_868[];
-
         static std::string JoinModeStr(uint8_t mode);
         static std::string ModeStr(uint8_t mode);
         static std::string RxOutputStr(uint8_t format);
@@ -275,6 +263,13 @@
          */
         static mDot* getInstance(lora::ChannelPlan* plan);
 
+        /**
+	 * Can only be used after a dot has 
+         * configured with a plan
+         * @returns pointer to mDot object
+         */
+        static mDot* getInstance();
+
         void setEvents(mDotEvent* events);
 
         /**
@@ -521,19 +516,32 @@
         void setListenBeforeTalkTime(uint32_t ms);
 
         /**
-         * Enable/disable public network mode
-         * JoinDelay will be set to (public: 5s, private: 1s) and
-         * RxDelay will be set to 1s both can be adjusted afterwards
-         * @param on should be true to enable public network mode
+         * Set public network mode
+         * 0:PRIVATE_MTS, 1:PUBLIC_LORAWAN, 2:PRIVATE_LORAWAN
+         * PRIVATE_MTS - Sync Word 0x12, US/AU Downlink frequencies per Frequency Sub Band
+         * PUBLIC_LORAWAN - Sync Word 0x34
+         * PRIVATE_LORAWAN - Sync Word 0x12
+         *
+         * The default Join Delay is 5 seconds
+         * The default Join Delay for PRIVATE_MTS was 1 second in the previous release
+         * The Join Delay must be changed independently of Public Network setting
+         *
+         * @see lora::NetworkType
          * @returns MDOT_OK if success
          */
-        int32_t setPublicNetwork(const bool& on);
+        int32_t setPublicNetwork(const uint8_t& val);
 
         /**
          * Get public network mode
-         * @returns true if public network mode is enabled
+         *
+         * The default Join Delay is 5 seconds
+         * The default Join Delay for PRIVATE_MTS was 1 second in the previous release
+         * The Join Delay must be changed independently of Public Network setting
+         *
+         * @see lora:NetworkType
+         * @returns 0:PRIVATE_MTS, 1:PUBLIC_LORAWAN, 2:PRIVATE_LORAWAN
          */
-        bool getPublicNetwork();
+        uint8_t getPublicNetwork();
 
         /**
          * Get the device ID
@@ -702,6 +710,19 @@
         const uint8_t* getAppKey();
 
         /**
+         * Add a multicast session address and keys
+         * Downlink counter is set to 0
+         * Up to 3 MULTICAST_SESSIONS can be set
+         */
+        int32_t setMulticastSession(uint8_t index, uint32_t addr, const uint8_t* nsk, const uint8_t* dsk);
+
+        /**
+         * Set a multicast session counter
+         * Up to 3 MULTICAST_SESSIONS can be set
+         */
+        int32_t setMulticastDownlinkCounter(uint8_t index, uint32_t count);
+
+        /**
          * Set join byte order
          * @param order 0:LSB 1:MSB
          */
@@ -883,16 +904,24 @@
 
         /**
          * Get join delay in seconds
-         *  Public network defaults to 5 seconds
-         *  Private network defaults to 1 second
+         *  Defaults to 5 seconds
+         *  Must match join delay setting of the network server
+         *
+         * The default Join Delay is 5 seconds
+         * The default Join Delay for PRIVATE_MTS was 1 second in the previous release
+         *
          *  @returns number of seconds before join accept message is expected
          */
         uint8_t getJoinDelay();
 
         /**
          * Set join delay in seconds
-         *  Public network defaults to 5 seconds
-         *  Private network defaults to 1 second
+         *  Defaults to 5 seconds
+         *  Must match join delay setting of the network server
+         *
+         * The default Join Delay is 5 seconds
+         * The default Join Delay for PRIVATE_MTS was 1 second in the previous release
+         *
          *  @param delay number of seconds before join accept message is expected
          *  @return MDOT_OK if success
          */
@@ -999,7 +1028,7 @@
         /**
          * Set TX data rate
          * data rates affect maximum payload size
-         * @param dr SF_7 - SF_12|DR0-DR7 for Europe, SF_7 - SF_10 | DR0-DR4 for United States
+         * @param dr DR0-DR7 for Europe, DR0-DR4 for United States
          * @returns MDOT_OK if success
          */
         int32_t setTxDataRate(const uint8_t& dr);
@@ -1298,8 +1327,24 @@
          * For the XDOT
          *      in sleep mode, the device can be woken up on GPIO (0-3), UART1_RX, WAKE or by the RTC alarm
          *      in deepsleep mode, the device can only be woken up using the WKUP pin (PA0, WAKE) or by the RTC alarm
+         * @returns MDOT_OK on success
          */
-        void sleep(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM, const bool& deepsleep = true);
+        int32_t sleep(const uint32_t& interval, const uint8_t& wakeup_mode = RTC_ALARM, const bool& deepsleep = true);
+
+        /**
+         * Set auto sleep mode
+         * Auto sleep mode will automatically put the MCU to sleep after tx and in between receive windows
+         * Note: The MCU will go into a stop mode sleep in between rx windows.  This means that
+         *       peripherals such as timers will not function during the sleep intervals.
+         * @param enable - Flag to enable auto sleep mode
+         */
+        void setAutoSleep(bool enable);
+
+        /**
+         * Get auto sleep mode
+         * @returns 0 if sleep mode is disabled, 1 if it is enabled
+         */
+        uint8_t getAutoSleep();
 
         /**
          * Set wake pin
@@ -1601,8 +1646,11 @@
         void closeRxWindow();
         void sendContinuous(bool enable=true);
         int32_t setDeviceId(const std::vector<uint8_t>& id);
+        int32_t setProtectedAppEUI(const std::vector<uint8_t>& appEUI);
+        int32_t setProtectedAppKey(const std::vector<uint8_t>& appKey);
         int32_t setDefaultFrequencyBand(const uint8_t& band);
         bool saveProtectedConfig();
+        // resets the radio/mac/link 
         void resetRadio();
         int32_t setRadioMode(const uint8_t& mode);
         std::map<uint8_t, uint8_t> dumpRegisters();
@@ -1629,8 +1677,35 @@
         void setWakeupCallback(T *object, void (T::*member)(void)) {
             _wakeup_callback.attach(object, member);
         }
+        
+        lora::ChannelPlan* getChannelPlan(void);  
 
+        uint32_t setRx2DataRate(uint8_t dr);
+        uint8_t getRx2DataRate();
+
+        void mcGroupKeys(uint8_t *mcKeyEncrypt, uint32_t addr, uint8_t groupId, uint32_t frame_count);  
     private:
+        typedef enum {
+            AUTO_SLEEP_EVT_CFG,
+            AUTO_SLEEP_EVT_TXDONE,
+            AUTO_SLEEP_EVT_RX1_TIMEOUT,
+            AUTO_SLEEP_EVT_CLEANUP
+        } AutoSleepEvent_t;
+
+        typedef enum {
+            USER_SLEEP,
+            AUTO_SLEEP
+        } SleepClient_t;
+
+        void sleep_ms(uint32_t interval,
+                      uint8_t wakeup_mode = RTC_ALARM,
+                      bool deepsleep = true,
+                      SleepClient_t sleep_client = USER_SLEEP);
+
+        void auto_sleep(AutoSleepEvent_t evt);
+
+        void wakeup(SleepClient_t sleep_client);
+
         mdot_stats _stats;
 
         FunctionPointer _wakeup_callback;