Bleeding edge development version of the mDot library. This version of the library is not guaranteed to be stable or well tested and should not be used in production or deployment scenarios.
Dependents: mDot_LoRa_CLASS_C_P2P
Fork of libmDot-dev by
Warning
Using libmDot 2.0.3 and above with an existing application may require a change in the MacEvent handler!
Compile applications with mbed v121 and mbed-rtos v116 libraries.
In AT Command Firmware remove line 803.
CommandTerminal/CommandTerminal.cpp
delete[] info->RxBuffer;
Likewise, if your application is handling events from the library asynchronously.
README.txt@13:5ac2300dc06a, 2016-03-29 (annotated)
- Committer:
- Mike Fiore
- Date:
- Tue Mar 29 10:20:45 2016 -0500
- Revision:
- 13:5ac2300dc06a
- Parent:
- 3:5e805b567124
reorganize source
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 |
13:5ac2300dc06a | 9 | The mDot header has documentation for all the public functions that will be useful to consumers of the library. |
Mike Fiore |
1:9f30fbe9e9c1 | 10 | |
Mike Fiore |
13:5ac2300dc06a | 11 | The following source code provides an example application which configures the mDot, connects to a MultiTech Conduit gateway with matching configuration, and sends data packets to the gateway. |
Mike Fiore |
2:6385bf37bfe7 | 12 | |
Mike Fiore |
1:9f30fbe9e9c1 | 13 | /************** |
Mike Fiore |
1:9f30fbe9e9c1 | 14 | SAMPLE CODE |
Mike Fiore |
1:9f30fbe9e9c1 | 15 | **************/ |
Mike Fiore |
1:9f30fbe9e9c1 | 16 | |
Mike Fiore |
1:9f30fbe9e9c1 | 17 | #include "mbed.h" |
Mike Fiore |
1:9f30fbe9e9c1 | 18 | #include "mDot.h" |
Mike Fiore |
1:9f30fbe9e9c1 | 19 | #include <string> |
Mike Fiore |
1:9f30fbe9e9c1 | 20 | #include <vector> |
Mike Fiore |
1:9f30fbe9e9c1 | 21 | |
Mike Fiore |
1:9f30fbe9e9c1 | 22 | // these options must match the settings on your Conduit in |
Mike Fiore |
1:9f30fbe9e9c1 | 23 | // /var/config/lora/lora-network-server.conf |
Mike Fiore |
1:9f30fbe9e9c1 | 24 | static std::string config_network_name = "my_lora_network"; |
Mike Fiore |
1:9f30fbe9e9c1 | 25 | static std::string config_network_pass = "my_network_password"; |
Mike Fiore |
1:9f30fbe9e9c1 | 26 | static uint8_t config_frequency_sub_band = 1; |
Mike Fiore |
1:9f30fbe9e9c1 | 27 | |
Mike Fiore |
1:9f30fbe9e9c1 | 28 | void log_error(mDot* dot, const char* msg, int32_t retval); |
Mike Fiore |
1:9f30fbe9e9c1 | 29 | |
Mike Fiore |
1:9f30fbe9e9c1 | 30 | int main() { |
Mike Fiore |
1:9f30fbe9e9c1 | 31 | int32_t ret; |
Mike Fiore |
1:9f30fbe9e9c1 | 32 | mDot* dot; |
Mike Fiore |
1:9f30fbe9e9c1 | 33 | std::vector<uint8_t> data; |
Mike Fiore |
1:9f30fbe9e9c1 | 34 | std::string data_str = "hello world!"; |
Mike Fiore |
1:9f30fbe9e9c1 | 35 | |
Mike Fiore |
1:9f30fbe9e9c1 | 36 | // get a mDot handle |
Mike Fiore |
1:9f30fbe9e9c1 | 37 | dot = mDot::getInstance(); |
Mike Fiore |
1:9f30fbe9e9c1 | 38 | |
Mike Fiore |
1:9f30fbe9e9c1 | 39 | // reset to default config so we know what state we're in |
Mike Fiore |
1:9f30fbe9e9c1 | 40 | dot->resetConfig(); |
Mike Fiore |
1:9f30fbe9e9c1 | 41 | |
Mike Fiore |
1:9f30fbe9e9c1 | 42 | // print library version information |
Mike Fiore |
1:9f30fbe9e9c1 | 43 | printf("version: %s\r\n", dot->getId().c_str()); |
Mike Fiore |
1:9f30fbe9e9c1 | 44 | |
Mike Fiore |
1:9f30fbe9e9c1 | 45 | // set up the mDot with our network information |
Mike Fiore |
1:9f30fbe9e9c1 | 46 | printf("setting frequency sub band\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 47 | if ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 48 | log_error(dot, "failed to set frequency sub band", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 49 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 50 | printf("setting network name\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 51 | if ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 52 | log_error(dot, "failed to set network name", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 53 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 54 | printf("setting network password\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 55 | if ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 56 | log_error(dot, "failed to set network password", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 57 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 58 | |
Mike Fiore |
1:9f30fbe9e9c1 | 59 | // attempt to join the network |
Mike Fiore |
1:9f30fbe9e9c1 | 60 | printf("joining network\r\n"); |
Mike Fiore |
3:5e805b567124 | 61 | while ((ret = dot->joinNetwork()) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 62 | log_error(dot, "failed to join network", ret); |
Mike Fiore |
3:5e805b567124 | 63 | wait(2); |
Mike Fiore |
1:9f30fbe9e9c1 | 64 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 65 | |
Mike Fiore |
1:9f30fbe9e9c1 | 66 | // format data for sending to the gateway |
Mike Fiore |
1:9f30fbe9e9c1 | 67 | for (std::string::iterator it = data_str.begin(); it != data_str.end(); it++) |
Mike Fiore |
1:9f30fbe9e9c1 | 68 | data.push_back((uint8_t) *it); |
Mike Fiore |
1:9f30fbe9e9c1 | 69 | |
Mike Fiore |
1:9f30fbe9e9c1 | 70 | while (true) { |
Mike Fiore |
1:9f30fbe9e9c1 | 71 | // send the data |
Mike Fiore |
1:9f30fbe9e9c1 | 72 | // ACKs are enabled by default, so we're expecting to get one back |
Mike Fiore |
1:9f30fbe9e9c1 | 73 | if ((ret = dot->send(data)) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 74 | log_error(dot, "failed to send", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 75 | } else { |
Mike Fiore |
1:9f30fbe9e9c1 | 76 | printf("successfully sent data to gateway\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 77 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 78 | |
Mike Fiore |
1:9f30fbe9e9c1 | 79 | wait(5); |
Mike Fiore |
1:9f30fbe9e9c1 | 80 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 81 | |
Mike Fiore |
1:9f30fbe9e9c1 | 82 | return 0; |
Mike Fiore |
1:9f30fbe9e9c1 | 83 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 84 | |
Mike Fiore |
1:9f30fbe9e9c1 | 85 | void log_error(mDot* dot, const char* msg, int32_t retval) { |
Mike Fiore |
1:9f30fbe9e9c1 | 86 | printf("%s - %ld:%s, %s\r\n", msg, retval, mDot::getReturnCodeString(retval).c_str(), dot->getLastError().c_str()); |
Mike Fiore |
1:9f30fbe9e9c1 | 87 | } |