Skip to content

Commit 87f33a9

Browse files
author
Hasnain Virk
committed
Making items configurable through json
Following the fashion of other mbed-os examples, we are making cellular items like pin code, APN etc configurable through json file.
1 parent 329fc7a commit 87f33a9

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

main.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,30 @@
77
#define TCP 1
88

99
// SIM pin code goes here
10-
#define PIN_CODE "1234"
10+
#ifndef MBED_CONF_APP_SIM_PIN_CODE
11+
# define MBED_CONF_APP_SIM_PIN_CODE "1234"
12+
#endif
1113

12-
// Network credentials like APN go here, e.g.,
13-
// "apn, username, password"
14-
#define CREDENTIALS "internet"
14+
#ifndef MBED_CONF_APP_APN
15+
# define MBED_CONF_APP_APN "internet"
16+
#endif
17+
#ifndef MBED_CONF_APP_USERNAME
18+
# define MBED_CONF_APP_USERNAME NULL
19+
#endif
20+
#ifndef MBED_CONF_APP_PASSWORD
21+
# define MBED_CONF_APP_PASSWORD NULL
22+
#endif
1523

1624
// Number of retries /
1725
#define RETRY_COUNT 3
1826

1927
// CellularInterface object
2028
OnboardCellularInterface iface;
2129

22-
// NIST ntp hostname
30+
// Echo server hostname
2331
const char *host_name = "echo.u-blox.com";
2432

25-
// NIST ntp port
33+
// Echo server port (same for TCP and UDP)
2634
const int port = 7;
2735

2836
/**
@@ -135,10 +143,10 @@ int main()
135143
{
136144
iface.modem_debug_on(MBED_CONF_APP_MODEM_TRACE);
137145
/* Set Pin code for SIM card */
138-
iface.set_sim_pin(PIN_CODE);
146+
iface.set_sim_pin(MBED_CONF_APP_SIM_PIN_CODE);
139147

140148
/* Set network credentials here, e.g., APN*/
141-
iface.set_credentials(CREDENTIALS);
149+
iface.set_credentials(MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME, MBED_CONF_APP_PASSWORD);
142150

143151
printf("\n\nmbed-os-example-cellular, Connecting...\n");
144152

mbed_app.json

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
{
2-
"config": {
3-
"sock-type": "UDP",
4-
"modem_trace": false
2+
"config": {
3+
"sock-type": "UDP",
4+
"modem_trace": {
5+
"help": "Turns AT command trace on/off from the cellular modem, defaults to off",
6+
"value": false
7+
},
8+
"sim-pin-code": {
9+
"help": "SIM PIN code",
10+
"value": "\"1234\""
11+
},
12+
"apn": {
13+
"help": "The APN string to use for this SIM/network, set to 0 if none",
14+
"value": "\"internet\""
15+
},
16+
"username": {
17+
"help": "The user name string to use for this APN, set to zero if none",
18+
"value": 0
19+
},
20+
"password": {
21+
"help": "The password string to use for this APN, set to 0 if none",
22+
"value": 0
23+
}
524
},
625
"target_overrides": {
726
"*": {

0 commit comments

Comments
 (0)