Ram Gandikota
/
metronome
FRDM K64F Metronome
easy-connect/README.md@0:a2cb7295a1f7, 2017-05-14 (annotated)
- Committer:
- ram54288
- Date:
- Sun May 14 18:35:07 2017 +0000
- Revision:
- 0:a2cb7295a1f7
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ram54288 | 0:a2cb7295a1f7 | 1 | # Easy Connect - Easily add all supported connectivity methods to your mbed OS project |
ram54288 | 0:a2cb7295a1f7 | 2 | |
ram54288 | 0:a2cb7295a1f7 | 3 | Often you want to give users of your application the choice to switch between connectivity methods. The `NetworkInterface` API makes this easy, but you'll still need a mechanism for the user to chooce the method, throw in some `#define`'s, etc. Easy Connect handles all this for you. Just declare the desired connectivity method in your `mbed_app.json` file, and call `easy_connect()` from your application. |
ram54288 | 0:a2cb7295a1f7 | 4 | |
ram54288 | 0:a2cb7295a1f7 | 5 | ## Specifying connectivity method |
ram54288 | 0:a2cb7295a1f7 | 6 | |
ram54288 | 0:a2cb7295a1f7 | 7 | Add the following to your ``mbed_app.json`` file: |
ram54288 | 0:a2cb7295a1f7 | 8 | |
ram54288 | 0:a2cb7295a1f7 | 9 | ```json |
ram54288 | 0:a2cb7295a1f7 | 10 | { |
ram54288 | 0:a2cb7295a1f7 | 11 | "config": { |
ram54288 | 0:a2cb7295a1f7 | 12 | "network-interface":{ |
ram54288 | 0:a2cb7295a1f7 | 13 | "help": "options are ETHERNET,WIFI_ESP8266,WIFI_ODIN,MESH_LOWPAN_ND,MESH_THREAD", |
ram54288 | 0:a2cb7295a1f7 | 14 | "value": "ETHERNET" |
ram54288 | 0:a2cb7295a1f7 | 15 | } |
ram54288 | 0:a2cb7295a1f7 | 16 | }, |
ram54288 | 0:a2cb7295a1f7 | 17 | "target_overrides": { |
ram54288 | 0:a2cb7295a1f7 | 18 | "*": { |
ram54288 | 0:a2cb7295a1f7 | 19 | "target.features_add": ["NANOSTACK", "LOWPAN_ROUTER", "COMMON_PAL"], |
ram54288 | 0:a2cb7295a1f7 | 20 | "mbed-mesh-api.6lowpan-nd-channel-page": 0, |
ram54288 | 0:a2cb7295a1f7 | 21 | "mbed-mesh-api.6lowpan-nd-channel": 12 |
ram54288 | 0:a2cb7295a1f7 | 22 | } |
ram54288 | 0:a2cb7295a1f7 | 23 | } |
ram54288 | 0:a2cb7295a1f7 | 24 | } |
ram54288 | 0:a2cb7295a1f7 | 25 | ``` |
ram54288 | 0:a2cb7295a1f7 | 26 | |
ram54288 | 0:a2cb7295a1f7 | 27 | If you choose `WIFI_ESP8266` or `WIFI_ODIN`, you'll also need to add the WiFi SSID and password: |
ram54288 | 0:a2cb7295a1f7 | 28 | |
ram54288 | 0:a2cb7295a1f7 | 29 | ```json |
ram54288 | 0:a2cb7295a1f7 | 30 | "config": { |
ram54288 | 0:a2cb7295a1f7 | 31 | "network-interface":{ |
ram54288 | 0:a2cb7295a1f7 | 32 | "help": "options are ETHERNET,WIFI_ESP8266,WIFI_ODIN,MESH_LOWPAN_ND,MESH_THREAD", |
ram54288 | 0:a2cb7295a1f7 | 33 | "value": "WIFI_ESP8266" |
ram54288 | 0:a2cb7295a1f7 | 34 | }, |
ram54288 | 0:a2cb7295a1f7 | 35 | "esp8266-tx": { |
ram54288 | 0:a2cb7295a1f7 | 36 | "help": "Pin used as TX (connects to ESP8266 RX)", |
ram54288 | 0:a2cb7295a1f7 | 37 | "value": "PTD3" |
ram54288 | 0:a2cb7295a1f7 | 38 | }, |
ram54288 | 0:a2cb7295a1f7 | 39 | "esp8266-rx": { |
ram54288 | 0:a2cb7295a1f7 | 40 | "help": "Pin used as RX (connects to ESP8266 TX)", |
ram54288 | 0:a2cb7295a1f7 | 41 | "value": "PTD2" |
ram54288 | 0:a2cb7295a1f7 | 42 | }, |
ram54288 | 0:a2cb7295a1f7 | 43 | "esp8266-debug": { |
ram54288 | 0:a2cb7295a1f7 | 44 | "value": true |
ram54288 | 0:a2cb7295a1f7 | 45 | }, |
ram54288 | 0:a2cb7295a1f7 | 46 | "wifi-ssid": { |
ram54288 | 0:a2cb7295a1f7 | 47 | "value": "\"SSID\"" |
ram54288 | 0:a2cb7295a1f7 | 48 | }, |
ram54288 | 0:a2cb7295a1f7 | 49 | "wifi-password": { |
ram54288 | 0:a2cb7295a1f7 | 50 | "value": "\"Password\"" |
ram54288 | 0:a2cb7295a1f7 | 51 | } |
ram54288 | 0:a2cb7295a1f7 | 52 | } |
ram54288 | 0:a2cb7295a1f7 | 53 | ``` |
ram54288 | 0:a2cb7295a1f7 | 54 | |
ram54288 | 0:a2cb7295a1f7 | 55 | If you use `MESH_LOWPAN_ND` or `MESH_THREAD` you will need to specify your radio module: |
ram54288 | 0:a2cb7295a1f7 | 56 | |
ram54288 | 0:a2cb7295a1f7 | 57 | ```json |
ram54288 | 0:a2cb7295a1f7 | 58 | "config": { |
ram54288 | 0:a2cb7295a1f7 | 59 | "network-interface":{ |
ram54288 | 0:a2cb7295a1f7 | 60 | "help": "options are ETHERNET,WIFI_ESP8266,WIFI_ODIN,MESH_LOWPAN_ND,MESH_THREAD", |
ram54288 | 0:a2cb7295a1f7 | 61 | "value": "MESH_LOWPAN_ND" |
ram54288 | 0:a2cb7295a1f7 | 62 | }, |
ram54288 | 0:a2cb7295a1f7 | 63 | "mesh_radio_type": { |
ram54288 | 0:a2cb7295a1f7 | 64 | "help": "options are ATMEL, MCR20", |
ram54288 | 0:a2cb7295a1f7 | 65 | "value": "ATMEL" |
ram54288 | 0:a2cb7295a1f7 | 66 | } |
ram54288 | 0:a2cb7295a1f7 | 67 | } |
ram54288 | 0:a2cb7295a1f7 | 68 | ``` |
ram54288 | 0:a2cb7295a1f7 | 69 | |
ram54288 | 0:a2cb7295a1f7 | 70 | ## Using Easy Connect from your application |
ram54288 | 0:a2cb7295a1f7 | 71 | |
ram54288 | 0:a2cb7295a1f7 | 72 | Easy Connect has just one function which will either return a `NetworkInterface`-pointer or `NULL`: |
ram54288 | 0:a2cb7295a1f7 | 73 | |
ram54288 | 0:a2cb7295a1f7 | 74 | ```cpp |
ram54288 | 0:a2cb7295a1f7 | 75 | #include "easy-connect.h" |
ram54288 | 0:a2cb7295a1f7 | 76 | |
ram54288 | 0:a2cb7295a1f7 | 77 | int main(int, char**) { |
ram54288 | 0:a2cb7295a1f7 | 78 | NetworkInterface* network = easy_connect(true); /* has 1 argument, enable_logging (pass in true to log to serial port) */ |
ram54288 | 0:a2cb7295a1f7 | 79 | if (!network) { |
ram54288 | 0:a2cb7295a1f7 | 80 | printf("Connecting to the network failed... See serial output.\r\n"); |
ram54288 | 0:a2cb7295a1f7 | 81 | return 1; |
ram54288 | 0:a2cb7295a1f7 | 82 | } |
ram54288 | 0:a2cb7295a1f7 | 83 | |
ram54288 | 0:a2cb7295a1f7 | 84 | // Rest of your program |
ram54288 | 0:a2cb7295a1f7 | 85 | } |
ram54288 | 0:a2cb7295a1f7 | 86 | ``` |
ram54288 | 0:a2cb7295a1f7 | 87 | ## CR/LF in serial output |
ram54288 | 0:a2cb7295a1f7 | 88 | |
ram54288 | 0:a2cb7295a1f7 | 89 | If you want to avoid using `\r\n` in your printouts and just use normal C-style `\n` instead, please specify these to your `mbed_app.json` |
ram54288 | 0:a2cb7295a1f7 | 90 | |
ram54288 | 0:a2cb7295a1f7 | 91 | ```json |
ram54288 | 0:a2cb7295a1f7 | 92 | "target_overrides": { |
ram54288 | 0:a2cb7295a1f7 | 93 | "*": { |
ram54288 | 0:a2cb7295a1f7 | 94 | "platform.stdio-baud-rate": 115200, |
ram54288 | 0:a2cb7295a1f7 | 95 | "platform.stdio-convert-newlines": true |
ram54288 | 0:a2cb7295a1f7 | 96 | } |
ram54288 | 0:a2cb7295a1f7 | 97 | } |
ram54288 | 0:a2cb7295a1f7 | 98 | ``` |
ram54288 | 0:a2cb7295a1f7 | 99 | |
ram54288 | 0:a2cb7295a1f7 | 100 | ## Extra defines |
ram54288 | 0:a2cb7295a1f7 | 101 | |
ram54288 | 0:a2cb7295a1f7 | 102 | If you'd like to use Easy Connect with mbed Client then you're in luck. Easy Connect automatically defines the `MBED_SERVER_ADDRESS` macro depending on your connectivity method (either IPv4 or IPv6 address). Use this address to connect to the right instance of mbed Device Connector. |