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

Commit 36aaf6b

Browse files
authored
Merge pull request #23 from ARMmbed/updated-config
Updating mbed_app.json
2 parents c78f3ad + 565f092 commit 36aaf6b

File tree

4 files changed

+64
-39
lines changed

4 files changed

+64
-39
lines changed

MACROS.txt

Lines changed: 0 additions & 3 deletions
This file was deleted.

README.md

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,13 @@ To configure the example application, please:
3939

4040
### Connection type
4141

42-
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:
42+
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:
4343

4444
```
45-
#undef ETHERNET
46-
#undef WIFI
47-
#undef CELLULAR
48-
#define MESH_LOWPAN_ND
49-
#undef MESH_THREAD
45+
"network-interface":{
46+
"help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.",
47+
"value": "MESH_LOWPAN_ND"
48+
},
5049
```
5150

5251
### Client credentials
@@ -122,11 +121,24 @@ The example application uses ESP8266 WiFi Interface for managing the wireless co
122121
1. Have [ESP8266](https://en.wikipedia.org/wiki/ESP8266) WiFi module running [Espressif Firmware](https://codeload.github.com/espressif/ESP8266_AT/zip/master)
123122
1. Mount WiFi module onto [K64F Grove Shield v2](https://developer.mbed.org/platforms/FRDM-K64F/#supported-seeed-studio-grove-extension)
124123
1. Attach the shield on the K64F board.
125-
1. In the `main.cpp` file:
126-
- set WIFI as defined and other connection types as undefined.
127-
- remove `#error "Remember to provide your WiFi credentials and provide in esp.connect("ssid","password");"`
128-
- `esp.connect("ssid", "password");` , replace `ssid` and `password` with your WiFi SSID and WiFi password respectively.
129-
124+
1. In the `mbed_app.json` file, change
125+
```
126+
"network-interface":{
127+
"help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD.",
128+
"value": "WIFI"
129+
},
130+
```
131+
1. Provide your WiFi SSID and password here
132+
```
133+
"wifi-ssid": {
134+
"help": "WiFi SSID",
135+
"value": "\"IoTBU-Sniffer\""
136+
},
137+
"wifi-password": {
138+
"help": "WiFi Password",
139+
"value": "\"AppleBearWireCube\""
140+
}
141+
```
130142

131143
### IP address setup
132144

main.cpp

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,24 @@
2424
#include "mbed.h"
2525
#include "rtos.h"
2626

27-
#define ETHERNET
28-
#undef WIFI
29-
#undef CELLULAR
30-
#undef MESH_LOWPAN_ND
31-
#undef MESH_THREAD
27+
#define ETHERNET 1
28+
#define WIFI 2
29+
#define MESH_LOWPAN_ND 3
30+
#define MESH_THREAD 4
3231

33-
#if defined WIFI
32+
#define STRINGIFY(s) #s
33+
34+
#if MBED_CONF_APP_NETWORK_INTERFACE == WIFI
3435
#include "ESP8266Interface.h"
3536
ESP8266Interface esp(D1, D0);
36-
#elif defined (CELLULAR)
37-
#include "C027Interface.h"
38-
C027Interface c027;
39-
#elif defined (ETHERNET)
37+
#elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET
4038
#include "LWIPInterface.h"
4139
LWIPInterface lwip;
42-
#elif defined (MESH_LOWPAN_ND)
40+
#elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_LOWPAN_ND
4341
#define MESH
4442
#include "NanostackInterface.h"
4543
LoWPANNDInterface mesh;
46-
#elif defined (MESH_THREAD)
44+
#elif MBED_CONF_APP_NETWORK_INTERFACE == MESH_THREAD
4745
#define MESH
4846
#include "NanostackInterface.h"
4947
ThreadInterface mesh;
@@ -54,7 +52,7 @@ ThreadInterface mesh;
5452
#define MBED_SERVER_ADDRESS "coap://api.connector.mbed.com:5684"
5553
#else
5654
// This is address to mbed Device Connector
57-
#define MBED_SERVER_ADDRESS YOTTA_CFG_DEVICE_CONNECTOR_URI
55+
#define MBED_SERVER_ADDRESS "coaps://[2607:f0d0:2601:52::20]:5684"
5856
#endif
5957

6058
Serial output(USBTX, USBRX);
@@ -255,25 +253,29 @@ int main() {
255253
mbed_trace_print_function_set(trace_printer);
256254

257255
NetworkStack *network_stack = 0;
258-
#if defined WIFI
256+
int connect_success = -1;
257+
#if MBED_CONF_APP_NETWORK_INTERFACE == WIFI
259258
output.printf("\n\rUsing WiFi \r\n");
260259
output.printf("\n\rConnecting to WiFi..\r\n");
261-
#error "Remember to provide your WiFi credentials and provide in esp.connect("ssid","password");"
262-
esp.connect("ssid", "password");
263-
output.printf("\n\rConnected to WiFi\r\n");
260+
connect_success = esp.connect(MBED_CONF_APP_WIFI_SSID, MBED_CONF_APP_WIFI_PASSWORD);
264261
network_stack = &esp;
265-
#elif defined ETHERNET
266-
lwip.connect();
262+
#elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET
267263
output.printf("Using Ethernet LWIP\r\n");
264+
connect_success = lwip.connect();
268265
network_stack = &lwip;
269-
#elif defined (CELLULAR)
270-
c027.connect();
271-
output.printf("Using Cellular C027\r\n");
272-
network_stack = &c027;
273-
#elif defined MESH
274-
mesh.connect();
266+
#endif
267+
#ifdef MESH
268+
output.printf("Using Mesh\r\n");
269+
output.printf("\n\rConnecting to Mesh..\r\n");
270+
connect_success = mesh.connect();
275271
network_stack = &mesh;
276272
#endif
273+
if(connect_success == 0) {
274+
output.printf("\n\rConnected to Network successfully\r\n");
275+
} else {
276+
output.printf("\n\rConnection to Network Failed %d! Exiting application....\r\n", connect_success);
277+
return 0;
278+
}
277279
const char *ip_addr = network_stack->get_ip_address();
278280
if (ip_addr) {
279281
output.printf("IP address %s\r\n", ip_addr);

mbed_app.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
{
2+
"config": {
3+
"network-interface":{
4+
"help": "options are ETHERNET,WIFI,MESH_LOWPAN_ND,MESH_THREAD",
5+
"value": "ETHERNET"
6+
},
7+
"wifi-ssid": {
8+
"help": "WiFi SSID",
9+
"value": "\"IoTBU-Sniffer\""
10+
},
11+
"wifi-password": {
12+
"help": "WiFi Password",
13+
"value": "\"AppleBearWireCube\""
14+
}
15+
},
216
"target_overrides": {
317
"*": {
418
"mbed-client.reconnection-count": 3,

0 commit comments

Comments
 (0)