Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Updating mbed_app.json #23

Merged
merged 1 commit into from
Jun 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions MACROS.txt

This file was deleted.

34 changes: 23 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
52 changes: 27 additions & 25 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 14 additions & 0 deletions mbed_app.json
Original file line number Diff line number Diff line change
@@ -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,
Expand Down