Stable version of the mDot library for mbed 5. This version of the library is suitable for deployment scenarios. See lastest commit message for version of mbed-os library that has been tested against.

Dependents:   mdot_two_way unh-hackathon-example unh-hackathon-example-raw TelitSensorToCloud ... more

Fork of libmDot-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

main.cpp

    // Initialize FOTA singleton
    Fota::getInstance(dot);
  • Add fragmentation handling the the PacketRx event

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
    }

A definition is needed to enable Fragmentation support on mDot and save fragments to flash. This should not be defined for xDot and will result in a compiler error.

mbed_app.json

{
    "macros": [
        "FOTA=1"
    ]
}

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:
16:b630e18103e5
Parent:
12:54f9cac9d690
Child:
17:306ffaa5d79b
--- a/mDot.h	Tue Mar 29 10:25:31 2016 -0500
+++ b/mDot.h	Thu Aug 04 15:11:24 2016 -0500
@@ -5,17 +5,16 @@
 
 #include "mbed.h"
 #include "rtos.h"
+#include "Mote.h"
 #include <vector>
 #include <map>
 #include <string>
 
 class mDotEvent;
-class LoRaMacEvent;
 class LoRaConfig;
-class LoRaMac;
-class MdotRadio;
 
 class mDot {
+        friend class mDotEvent;
 
     private:
 
@@ -27,6 +26,8 @@
                 __WFI();
         }
 
+        void initLora();
+
         void setLastError(const std::string& str);
 
         static bool validateBaudRate(const uint32_t& baud);
@@ -61,10 +62,11 @@
 
         static mDot* _instance;
 
-        LoRaMac* _mac;
-        MdotRadio* _radio;
-        LoRaMacEvent* _events;
+        lora::Mote _mote;
         LoRaConfig* _config;
+        lora::Settings _settings;
+        mDotEvent* _events;
+
         Thread _idle_thread;
         std::string _last_error;
         static const uint32_t _baud_rates[];
@@ -114,7 +116,7 @@
         } mdot_ret_code;
 
         enum JoinMode {
-            MANUAL,
+            MANUAL = 0,
             OTA,
             AUTO_OTA,
             PEER_TO_PEER
@@ -158,8 +160,11 @@
         };
 
         enum FrequencyBands {
-            FB_868, // EU868
-            FB_915  // US915
+            FB_868 = 0,
+            FB_915 = 1,
+            FB_EU868 = 0, // EU868
+            FB_US915 = 1,  // US915
+            FB_AU915 = 2
         };
 
         enum FrequencySubBands {
@@ -200,7 +205,7 @@
 
         typedef struct {
                 int16_t fd;
-                char name[30];
+                char name[33];
                 uint32_t size;
         } mdot_file;
 
@@ -210,6 +215,7 @@
                 uint32_t Joins;
                 uint32_t JoinFails;
                 uint32_t MissedAcks;
+                uint32_t CRCErrors;
         } mdot_stats;
 
         typedef struct {
@@ -332,6 +338,10 @@
          */
         bool getStandbyFlag();
 
+        std::vector<uint16_t> getChannelMask();
+
+        int32_t setChannelMask(uint8_t offset, uint16_t mask);
+
         /** Add a channel frequencies currently in use
          * @returns MDOT_OK
          */
@@ -680,6 +690,42 @@
          */
         uint32_t setJoinDelay(uint8_t delay);
 
+        /** Get join Rx1 datarate offset
+         *  defaults to 0
+         *  @returns offset
+         */
+        uint8_t getJoinRx1DataRateOffset();
+
+        /** Set join Rx1 datarate offset
+         *  @param offset for datarate
+         *  @return MDOT_OK if success
+         */
+        uint32_t setJoinRx1DataRateOffset(uint8_t offset);
+
+        /** Get join Rx2 datarate
+         *  defaults to US:DR8, AU:DR8, EU:DR0
+         *  @returns datarate
+         */
+        uint8_t getJoinRx2DataRate();
+
+        /** Set join Rx2 datarate
+         *  @param datarate
+         *  @return MDOT_OK if success
+         */
+        uint32_t setJoinRx2DataRate(uint8_t datarate);
+
+        /** Get join Rx2 frequency
+         *  defaults US:923.3, AU:923.3, EU:869.525
+         *  @returns frequency
+         */
+        uint32_t getJoinRx2Frequency();
+
+        /** Set join Rx2 frequency
+         *  @param frequency
+         *  @return MDOT_OK if success
+         */
+        uint32_t setJoinRx2Frequency(uint32_t frequency);
+
         /** Get rx delay in seconds
          *  Defaults to 1 second
          *  @returns number of seconds before response message is expected
@@ -712,11 +758,22 @@
          */
         bool getDataPending();
 
-        /** Get transmitting
+        /** Get ack requested
+         * only valid after sending data to the gateway
+         * @returns true if server has requested ack
+         */
+        bool getAckRequested();
+
+        /** Get is transmitting indicator
          * @returns true if currently transmitting
          */
         bool getIsTransmitting();
 
+        /** Get is idle indicator
+         * @returns true if not currently transmitting, waiting or receiving
+         */
+        bool getIsIdle();
+
         /** 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
@@ -734,7 +791,6 @@
          */
         uint32_t getRadioRandom();
 
-
         /** Get data rate spreading factor and bandwidth
          * EU868 Datarates
          * ---------------
@@ -795,6 +851,10 @@
          */
         bool getTxWait();
 
+        /** Cancel pending rx windows
+         */
+        void cancelRxWindow();
+
         /** Get time on air
          * @returns the amount of time (in ms) it would take to send bytes bytes based on current configuration
          */
@@ -869,6 +929,24 @@
          */
         int32_t send(const std::vector<uint8_t>& data, const bool& blocking = true, const bool& highBw = false);
 
+        /** Inject mac command
+         * @param data a vector containing mac commands
+         * @returns MDOT_OK
+         */
+        int32_t injectMacCommand(const std::vector<uint8_t>& data);
+
+        /**
+         * Clear MAC command buffer to be sent in next uplink
+         * @returns MDOT_OK
+         */
+        int32_t clearMacCommands();
+
+        /**
+         * Get MAC command buffer to be sent in next uplink
+         * @returns command bytes
+         */
+        std::vector<uint8_t> getMacCommands();
+
         /** Fetch data received from the gateway
          * this function only checks to see if a packet has been received - it does not open a receive window
          * send() must be called before recv()
@@ -1104,7 +1182,6 @@
         int32_t setFlowControl(const bool& on);
         bool getFlowControl();
 
-
         // get/set serial clear on error
         // if enabled the data read from the serial port will be discarded if it cannot be sent or if the send fails
         // set function returns MDOT_OK if success
@@ -1113,8 +1190,26 @@
 
         // MTS_RADIO_DEBUG_COMMANDS
 
+        /** Disable Duty cycle
+         * enables or disables the duty cycle limitations
+         * **** ONLY TO BE USED FOR TESTINGS PURPOSES ****
+         * **** ALL DEPLOYABLE CODE MUST ADHERE TO LOCAL REGULATIONS ****
+         * **** THIS SETTING WILL NOT BE SAVED TO CONFIGURATION *****
+         * @param val true to disable duty-cycle (default:false)
+         */
+        int32_t setDisableDutyCycle(bool val);
+
+        /** Disable Duty cycle
+         * **** ONLY TO BE USED FOR TESTINGS PURPOSES ****
+         * **** ALL DEPLOYABLE CODE MUST ADHERE TO LOCAL REGULATIONS ****
+         * **** THIS SETTING WILL NOT BE SAVED TO CONFIGURATION *****
+         * @return true if duty-cycle is disabled (default:false)
+         */
+        uint8_t getDisableDutyCycle();
+
         void openRxWindow(uint32_t timeout, uint8_t bandwidth = 0);
-        void sendContinuous();
+        void closeRxWindow();
+        void sendContinuous(bool enable=true);
         int32_t setDeviceId(const std::vector<uint8_t>& id);
         int32_t setFrequencyBand(const uint8_t& band);
         bool saveProtectedConfig();