Fork of my original MQTTGateway

Dependencies:   mbed-http

Committer:
vpcola
Date:
Sat Apr 08 14:43:14 2017 +0000
Revision:
0:a1734fe1ec4b
Initial commit

Who changed what in which revision?

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