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