FRDM K64F Metronome

Committer:
ram54288
Date:
Sun May 14 18:37:05 2017 +0000
Revision:
0:dbad57390bd1
Initial commit

Who changed what in which revision?

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