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
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
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
README.txt@1:9f30fbe9e9c1, 2015-06-24 (annotated)
- Committer:
- Mike Fiore
- Date:
- Wed Jun 24 17:03:08 2015 -0500
- Revision:
- 1:9f30fbe9e9c1
- Child:
- 2:6385bf37bfe7
add README, LICENSE, headers, and library - from git tag mbed_24June2015
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Mike Fiore |
1:9f30fbe9e9c1 | 1 | --------------------------------------- |
Mike Fiore |
1:9f30fbe9e9c1 | 2 | Getting Started with the mDot Library |
Mike Fiore |
1:9f30fbe9e9c1 | 3 | --------------------------------------- |
Mike Fiore |
1:9f30fbe9e9c1 | 4 | |
Mike Fiore |
1:9f30fbe9e9c1 | 5 | This README should get you started using the mDot library with your MultiTech mDot. |
Mike Fiore |
1:9f30fbe9e9c1 | 6 | |
Mike Fiore |
1:9f30fbe9e9c1 | 7 | License information can be found in the accompanying LICENSE file. |
Mike Fiore |
1:9f30fbe9e9c1 | 8 | |
Mike Fiore |
1:9f30fbe9e9c1 | 9 | The mDot header has documentation for all the public functions that will be useful to consumers of |
Mike Fiore |
1:9f30fbe9e9c1 | 10 | the library. |
Mike Fiore |
1:9f30fbe9e9c1 | 11 | |
Mike Fiore |
1:9f30fbe9e9c1 | 12 | The following source code provides an example application which configures the mDot, connects to a |
Mike Fiore |
1:9f30fbe9e9c1 | 13 | MultiTech Conduit gateway with matching configuration, and sends data packets to the gateway. |
Mike Fiore |
1:9f30fbe9e9c1 | 14 | |
Mike Fiore |
1:9f30fbe9e9c1 | 15 | /************** |
Mike Fiore |
1:9f30fbe9e9c1 | 16 | SAMPLE CODE |
Mike Fiore |
1:9f30fbe9e9c1 | 17 | **************/ |
Mike Fiore |
1:9f30fbe9e9c1 | 18 | |
Mike Fiore |
1:9f30fbe9e9c1 | 19 | #include "mbed.h" |
Mike Fiore |
1:9f30fbe9e9c1 | 20 | #include "mDot.h" |
Mike Fiore |
1:9f30fbe9e9c1 | 21 | #include <string> |
Mike Fiore |
1:9f30fbe9e9c1 | 22 | #include <vector> |
Mike Fiore |
1:9f30fbe9e9c1 | 23 | |
Mike Fiore |
1:9f30fbe9e9c1 | 24 | // these options must match the settings on your Conduit in |
Mike Fiore |
1:9f30fbe9e9c1 | 25 | // /var/config/lora/lora-network-server.conf |
Mike Fiore |
1:9f30fbe9e9c1 | 26 | static std::string config_network_name = "my_lora_network"; |
Mike Fiore |
1:9f30fbe9e9c1 | 27 | static std::string config_network_pass = "my_network_password"; |
Mike Fiore |
1:9f30fbe9e9c1 | 28 | static uint8_t config_frequency_sub_band = 1; |
Mike Fiore |
1:9f30fbe9e9c1 | 29 | |
Mike Fiore |
1:9f30fbe9e9c1 | 30 | void log_error(mDot* dot, const char* msg, int32_t retval); |
Mike Fiore |
1:9f30fbe9e9c1 | 31 | |
Mike Fiore |
1:9f30fbe9e9c1 | 32 | int main() { |
Mike Fiore |
1:9f30fbe9e9c1 | 33 | int32_t ret; |
Mike Fiore |
1:9f30fbe9e9c1 | 34 | mDot* dot; |
Mike Fiore |
1:9f30fbe9e9c1 | 35 | std::vector<uint8_t> data; |
Mike Fiore |
1:9f30fbe9e9c1 | 36 | std::string data_str = "hello world!"; |
Mike Fiore |
1:9f30fbe9e9c1 | 37 | |
Mike Fiore |
1:9f30fbe9e9c1 | 38 | // get a mDot handle |
Mike Fiore |
1:9f30fbe9e9c1 | 39 | dot = mDot::getInstance(); |
Mike Fiore |
1:9f30fbe9e9c1 | 40 | |
Mike Fiore |
1:9f30fbe9e9c1 | 41 | // reset to default config so we know what state we're in |
Mike Fiore |
1:9f30fbe9e9c1 | 42 | dot->resetConfig(); |
Mike Fiore |
1:9f30fbe9e9c1 | 43 | |
Mike Fiore |
1:9f30fbe9e9c1 | 44 | // print library version information |
Mike Fiore |
1:9f30fbe9e9c1 | 45 | printf("version: %s\r\n", dot->getId().c_str()); |
Mike Fiore |
1:9f30fbe9e9c1 | 46 | |
Mike Fiore |
1:9f30fbe9e9c1 | 47 | // set up the mDot with our network information |
Mike Fiore |
1:9f30fbe9e9c1 | 48 | printf("setting frequency sub band\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 49 | if ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 50 | log_error(dot, "failed to set frequency sub band", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 51 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 52 | printf("setting network name\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 53 | if ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 54 | log_error(dot, "failed to set network name", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 55 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 56 | printf("setting network password\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 57 | if ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 58 | log_error(dot, "failed to set network password", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 59 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 60 | |
Mike Fiore |
1:9f30fbe9e9c1 | 61 | // attempt to join the network |
Mike Fiore |
1:9f30fbe9e9c1 | 62 | printf("joining network\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 63 | if ((ret = dot->joinNetwork()) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 64 | log_error(dot, "failed to join network", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 65 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 66 | |
Mike Fiore |
1:9f30fbe9e9c1 | 67 | // format data for sending to the gateway |
Mike Fiore |
1:9f30fbe9e9c1 | 68 | for (std::string::iterator it = data_str.begin(); it != data_str.end(); it++) |
Mike Fiore |
1:9f30fbe9e9c1 | 69 | data.push_back((uint8_t) *it); |
Mike Fiore |
1:9f30fbe9e9c1 | 70 | |
Mike Fiore |
1:9f30fbe9e9c1 | 71 | while (true) { |
Mike Fiore |
1:9f30fbe9e9c1 | 72 | // send the data |
Mike Fiore |
1:9f30fbe9e9c1 | 73 | // ACKs are enabled by default, so we're expecting to get one back |
Mike Fiore |
1:9f30fbe9e9c1 | 74 | if ((ret = dot->send(data)) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 75 | log_error(dot, "failed to send", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 76 | } else { |
Mike Fiore |
1:9f30fbe9e9c1 | 77 | printf("successfully sent data to gateway\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 78 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 79 | |
Mike Fiore |
1:9f30fbe9e9c1 | 80 | wait(5); |
Mike Fiore |
1:9f30fbe9e9c1 | 81 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 82 | |
Mike Fiore |
1:9f30fbe9e9c1 | 83 | return 0; |
Mike Fiore |
1:9f30fbe9e9c1 | 84 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 85 | |
Mike Fiore |
1:9f30fbe9e9c1 | 86 | void log_error(mDot* dot, const char* msg, int32_t retval) { |
Mike Fiore |
1:9f30fbe9e9c1 | 87 | printf("%s - %ld:%s, %s\r\n", msg, retval, mDot::getReturnCodeString(retval).c_str(), dot->getLastError().c_str()); |
Mike Fiore |
1:9f30fbe9e9c1 | 88 | } |