Fork of my MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:45:51 2017 +0000
Revision:
0:f1d3878b8dd9
Initial commit

Who changed what in which revision?

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