libmDot0mbed5
Fork of libmDot-mbed5 by
README.txt@2:6385bf37bfe7, 2015-06-24 (annotated)
- Committer:
- Mike Fiore
- Date:
- Wed Jun 24 17:16:30 2015 -0500
- Revision:
- 2:6385bf37bfe7
- Parent:
- 1:9f30fbe9e9c1
- Child:
- 3:5e805b567124
update README with info about beta-newboards & mbed-src
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 |
2:6385bf37bfe7 | 15 | NOTE: All applications built using the mDot library must include mbed-src instead of mbed and must |
Mike Fiore |
2:6385bf37bfe7 | 16 | have the "newboards" beta token enabled. This is to resolve a stack size issue that may be |
Mike Fiore |
2:6385bf37bfe7 | 17 | encountered otherwise. A fix is on its way to the regular mbed library, but these extra steps are |
Mike Fiore |
2:6385bf37bfe7 | 18 | required until then. To enable the "newboards" beta token, go to the page listed below, click |
Mike Fiore |
2:6385bf37bfe7 | 19 | enable, and completely refresh your online compiler. |
Mike Fiore |
2:6385bf37bfe7 | 20 | |
Mike Fiore |
2:6385bf37bfe7 | 21 | https://developer.mbed.org/betamode/?pre=newboards |
Mike Fiore |
2:6385bf37bfe7 | 22 | |
Mike Fiore |
1:9f30fbe9e9c1 | 23 | /************** |
Mike Fiore |
1:9f30fbe9e9c1 | 24 | SAMPLE CODE |
Mike Fiore |
1:9f30fbe9e9c1 | 25 | **************/ |
Mike Fiore |
1:9f30fbe9e9c1 | 26 | |
Mike Fiore |
1:9f30fbe9e9c1 | 27 | #include "mbed.h" |
Mike Fiore |
1:9f30fbe9e9c1 | 28 | #include "mDot.h" |
Mike Fiore |
1:9f30fbe9e9c1 | 29 | #include <string> |
Mike Fiore |
1:9f30fbe9e9c1 | 30 | #include <vector> |
Mike Fiore |
1:9f30fbe9e9c1 | 31 | |
Mike Fiore |
1:9f30fbe9e9c1 | 32 | // these options must match the settings on your Conduit in |
Mike Fiore |
1:9f30fbe9e9c1 | 33 | // /var/config/lora/lora-network-server.conf |
Mike Fiore |
1:9f30fbe9e9c1 | 34 | static std::string config_network_name = "my_lora_network"; |
Mike Fiore |
1:9f30fbe9e9c1 | 35 | static std::string config_network_pass = "my_network_password"; |
Mike Fiore |
1:9f30fbe9e9c1 | 36 | static uint8_t config_frequency_sub_band = 1; |
Mike Fiore |
1:9f30fbe9e9c1 | 37 | |
Mike Fiore |
1:9f30fbe9e9c1 | 38 | void log_error(mDot* dot, const char* msg, int32_t retval); |
Mike Fiore |
1:9f30fbe9e9c1 | 39 | |
Mike Fiore |
1:9f30fbe9e9c1 | 40 | int main() { |
Mike Fiore |
1:9f30fbe9e9c1 | 41 | int32_t ret; |
Mike Fiore |
1:9f30fbe9e9c1 | 42 | mDot* dot; |
Mike Fiore |
1:9f30fbe9e9c1 | 43 | std::vector<uint8_t> data; |
Mike Fiore |
1:9f30fbe9e9c1 | 44 | std::string data_str = "hello world!"; |
Mike Fiore |
1:9f30fbe9e9c1 | 45 | |
Mike Fiore |
1:9f30fbe9e9c1 | 46 | // get a mDot handle |
Mike Fiore |
1:9f30fbe9e9c1 | 47 | dot = mDot::getInstance(); |
Mike Fiore |
1:9f30fbe9e9c1 | 48 | |
Mike Fiore |
1:9f30fbe9e9c1 | 49 | // reset to default config so we know what state we're in |
Mike Fiore |
1:9f30fbe9e9c1 | 50 | dot->resetConfig(); |
Mike Fiore |
1:9f30fbe9e9c1 | 51 | |
Mike Fiore |
1:9f30fbe9e9c1 | 52 | // print library version information |
Mike Fiore |
1:9f30fbe9e9c1 | 53 | printf("version: %s\r\n", dot->getId().c_str()); |
Mike Fiore |
1:9f30fbe9e9c1 | 54 | |
Mike Fiore |
1:9f30fbe9e9c1 | 55 | // set up the mDot with our network information |
Mike Fiore |
1:9f30fbe9e9c1 | 56 | printf("setting frequency sub band\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 57 | if ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 58 | log_error(dot, "failed to set frequency sub band", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 59 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 60 | printf("setting network name\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 61 | if ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 62 | log_error(dot, "failed to set network name", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 63 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 64 | printf("setting network password\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 65 | if ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 66 | log_error(dot, "failed to set network password", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 67 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 68 | |
Mike Fiore |
1:9f30fbe9e9c1 | 69 | // attempt to join the network |
Mike Fiore |
1:9f30fbe9e9c1 | 70 | printf("joining network\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 71 | if ((ret = dot->joinNetwork()) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 72 | log_error(dot, "failed to join network", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 73 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 74 | |
Mike Fiore |
1:9f30fbe9e9c1 | 75 | // format data for sending to the gateway |
Mike Fiore |
1:9f30fbe9e9c1 | 76 | for (std::string::iterator it = data_str.begin(); it != data_str.end(); it++) |
Mike Fiore |
1:9f30fbe9e9c1 | 77 | data.push_back((uint8_t) *it); |
Mike Fiore |
1:9f30fbe9e9c1 | 78 | |
Mike Fiore |
1:9f30fbe9e9c1 | 79 | while (true) { |
Mike Fiore |
1:9f30fbe9e9c1 | 80 | // send the data |
Mike Fiore |
1:9f30fbe9e9c1 | 81 | // ACKs are enabled by default, so we're expecting to get one back |
Mike Fiore |
1:9f30fbe9e9c1 | 82 | if ((ret = dot->send(data)) != mDot::MDOT_OK) { |
Mike Fiore |
1:9f30fbe9e9c1 | 83 | log_error(dot, "failed to send", ret); |
Mike Fiore |
1:9f30fbe9e9c1 | 84 | } else { |
Mike Fiore |
1:9f30fbe9e9c1 | 85 | printf("successfully sent data to gateway\r\n"); |
Mike Fiore |
1:9f30fbe9e9c1 | 86 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 87 | |
Mike Fiore |
1:9f30fbe9e9c1 | 88 | wait(5); |
Mike Fiore |
1:9f30fbe9e9c1 | 89 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 90 | |
Mike Fiore |
1:9f30fbe9e9c1 | 91 | return 0; |
Mike Fiore |
1:9f30fbe9e9c1 | 92 | } |
Mike Fiore |
1:9f30fbe9e9c1 | 93 | |
Mike Fiore |
1:9f30fbe9e9c1 | 94 | void log_error(mDot* dot, const char* msg, int32_t retval) { |
Mike Fiore |
1:9f30fbe9e9c1 | 95 | printf("%s - %ld:%s, %s\r\n", msg, retval, mDot::getReturnCodeString(retval).c_str(), dot->getLastError().c_str()); |
Mike Fiore |
1:9f30fbe9e9c1 | 96 | } |