diff --git a/MACROS.txt b/MACROS.txt deleted file mode 100644 index 72df7c457..000000000 --- a/MACROS.txt +++ /dev/null @@ -1,3 +0,0 @@ -TARGET_LIKE_MBED -YOTTA_CFG_MBED_TRACE -YOTTA_CFG_DEVICE_CONNECTOR_URI="coaps://[2607:f0d0:2601:52::20]:5684" diff --git a/README.md b/README.md index 81c6271e0..dea6b5e77 100755 --- a/README.md +++ b/README.md @@ -39,14 +39,13 @@ To configure the example application, please: ### Connection type -The application uses Ethernet as the default connection type. To change the connection type, set one of them as defined and all the rest as undefined in the beginning of the `main.cpp` file. For example, to enable 6LoWPAN ND mode: +The application uses Ethernet as the default connection type. To change the connection type, set one of them in `mbed_app.json`. For example, to enable 6LoWPAN ND mode: ``` -#undef ETHERNET -#undef WIFI -#undef CELLULAR -#define MESH_LOWPAN_ND -#undef MESH_THREAD + "network-interface":{ + "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.", + "value": "MESH_LOWPAN_ND" + }, ``` ### Client credentials @@ -122,11 +121,24 @@ The example application uses ESP8266 WiFi Interface for managing the wireless co 1. Have [ESP8266](https://en.wikipedia.org/wiki/ESP8266) WiFi module running [Espressif Firmware](https://codeload.github.com/espressif/ESP8266_AT/zip/master) 1. Mount WiFi module onto [K64F Grove Shield v2](https://developer.mbed.org/platforms/FRDM-K64F/#supported-seeed-studio-grove-extension) 1. Attach the shield on the K64F board. -1. In the `main.cpp` file: - - set WIFI as defined and other connection types as undefined. - - remove `#error "Remember to provide your WiFi credentials and provide in esp.connect("ssid","password");"` - - `esp.connect("ssid", "password");` , replace `ssid` and `password` with your WiFi SSID and WiFi password respectively. - +1. In the `mbed_app.json` file, change + ``` + "network-interface":{ + "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.", + "value": "WIFI" + }, + ``` +1. Provide your WiFi SSID and password here + ``` + "wifi-ssid": { + "help": "WiFi SSID", + "value": "\"IoTBU-Sniffer\"" + }, + "wifi-password": { + "help": "WiFi Password", + "value": "\"AppleBearWireCube\"" + } + ``` ### IP address setup diff --git a/main.cpp b/main.cpp index 6f6f59e83..c7c65f2a0 100644 --- a/main.cpp +++ b/main.cpp @@ -24,26 +24,24 @@ #include "mbed.h" #include "rtos.h" -#define ETHERNET -#undef WIFI -#undef CELLULAR -#undef MESH_LOWPAN_ND -#undef MESH_THREAD +#define ETHERNET 1 +#define WIFI 2 +#define MESH_LOWPAN_ND 3 +#define MESH_THREAD 4 -#if defined WIFI +#define STRINGIFY(s) #s + +#if MBED_CONF_APP_NETWORK_INTERFACE == WIFI #include "ESP8266Interface.h" ESP8266Interface esp(D1, D0); -#elif defined (CELLULAR) -#include "C027Interface.h" -C027Interface c027; -#elif defined (ETHERNET) +#elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET #include "LWIPInterface.h" LWIPInterface lwip; -#elif defined (MESH_LOWPAN_ND) +#elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_LOWPAN_ND #define MESH #include "NanostackInterface.h" LoWPANNDInterface mesh; -#elif defined (MESH_THREAD) +#elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_THREAD #define MESH #include "NanostackInterface.h" ThreadInterface mesh; @@ -54,7 +52,7 @@ ThreadInterface mesh; #define MBED_SERVER_ADDRESS "coap://api.connector.mbed.com:5684" #else // This is address to mbed Device Connector -#define MBED_SERVER_ADDRESS YOTTA_CFG_DEVICE_CONNECTOR_URI +#define MBED_SERVER_ADDRESS "coaps://[2607:f0d0:2601:52::20]:5684" #endif Serial output(USBTX, USBRX); @@ -255,25 +253,29 @@ int main() { mbed_trace_print_function_set(trace_printer); NetworkStack *network_stack = 0; -#if defined WIFI + int connect_success = -1; +#if MBED_CONF_APP_NETWORK_INTERFACE == WIFI output.printf("\n\rUsing WiFi \r\n"); output.printf("\n\rConnecting to WiFi..\r\n"); - #error "Remember to provide your WiFi credentials and provide in esp.connect("ssid","password");" - esp.connect("ssid", "password"); - output.printf("\n\rConnected to WiFi\r\n"); + connect_success = esp.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD); network_stack = &esp; -#elif defined ETHERNET - lwip.connect(); +#elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET output.printf("Using Ethernet LWIP\r\n"); + connect_success = lwip.connect(); network_stack = &lwip; -#elif defined (CELLULAR) - c027.connect(); - output.printf("Using Cellular C027\r\n"); - network_stack = &c027; -#elif defined MESH - mesh.connect(); +#endif +#ifdef MESH + output.printf("Using Mesh\r\n"); + output.printf("\n\rConnecting to Mesh..\r\n"); + connect_success = mesh.connect(); network_stack = &mesh; #endif + if(connect_success == 0) { + output.printf("\n\rConnected to Network successfully\r\n"); + } else { + output.printf("\n\rConnection to Network Failed %d! Exiting application....\r\n", connect_success); + return 0; + } const char *ip_addr = network_stack->get_ip_address(); if (ip_addr) { output.printf("IP address %s\r\n", ip_addr); diff --git a/mbed_app.json b/mbed_app.json index 526e70b47..e2accbfa3 100644 --- a/mbed_app.json +++ b/mbed_app.json @@ -1,4 +1,18 @@ { + "config": { + "network-interface":{ + "help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD", + "value": "ETHERNET" + }, + "wifi-ssid": { + "help": "WiFi SSID", + "value": "\"IoTBU-Sniffer\"" + }, + "wifi-password": { + "help": "WiFi Password", + "value": "\"AppleBearWireCube\"" + } + }, "target_overrides": { "*": { "mbed-client.reconnection-count": 3,