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