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

Commit b396fcf

Browse files
author
Janne Kiiskilä
authored
Merge pull request #61 from ARMmbed/getif
API to get network and WiFi interfaces w/o connecting
2 parents 15f9b1c + 398b862 commit b396fcf

File tree

2 files changed

+70
-1
lines changed

2 files changed

+70
-1
lines changed

easy-connect.cpp

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ char* _password = NULL;
117117
/* \brief print_MAC - print_MAC - helper function to print out MAC address
118118
* in: network_interface - pointer to network i/f
119119
* bool log-messages print out logs or not
120-
* MAC address is print, if it can be acquired & log_messages is true.
120+
* MAC address is printed, if it can be acquired & log_messages is true.
121121
*
122122
*/
123123
void print_MAC(NetworkInterface* network_interface, bool log_messages) {
@@ -139,6 +139,7 @@ void print_MAC(NetworkInterface* network_interface, bool log_messages) {
139139

140140
/* \brief easy_connect easy_connect() function to connect the pre-defined network bearer,
141141
* config done via mbed_app.json (see README.md for details).
142+
*
142143
* IN: bool log_messages print out diagnostics or not.
143144
*/
144145
NetworkInterface* easy_connect(bool log_messages) {
@@ -290,3 +291,55 @@ NetworkInterface* easy_connect(bool log_messages,
290291
#endif // EASY_CONNECT_WIFI
291292
return easy_connect(log_messages);
292293
}
294+
295+
/* \brief easy_get_netif - easy_connect function to get pointer to network interface
296+
* without connecting to it.
297+
*
298+
* IN: bool log_messages print out diagnostics or not.
299+
*/
300+
NetworkInterface* easy_get_netif(bool log_messages) {
301+
#if defined (EASY_CONNECT_WIFI)
302+
if (log_messages) {
303+
printf("[EasyConnect] WiFi: %s\n", EASY_CONNECT_WIFI_TYPE);
304+
}
305+
return &wifi;
306+
307+
#elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET
308+
if (log_messages) {
309+
printf("[EasyConnect] Ethernet\n");
310+
}
311+
return ð
312+
313+
#elif defined (EASY_CONNECT_MESH)
314+
if (log_messages) {
315+
printf("[EasyConnect] Mesh : %s\n", EASY_CONNECT_MESH_TYPE);
316+
}
317+
return &mesh;
318+
319+
#elif MBED_CONF_APP_NETWORK_INTERFACE == CELLULAR_ONBOARD
320+
if (log_messages) {
321+
printf("[EasyConnect] Cellular\n");
322+
}
323+
return &cellular;
324+
#endif
325+
}
326+
327+
/* \brief easy_get_wifi - easy_connect function to get pointer to Wifi interface
328+
* without connecting to it. You would want this 1st so that
329+
* you can scan the APNs, choose the right one and then connect.
330+
*
331+
* IN: bool log_messages print out diagnostics or not.
332+
*/
333+
WiFiInterface* easy_get_wifi(bool log_messages) {
334+
#if defined (EASY_CONNECT_WIFI)
335+
if (log_messages) {
336+
printf("[EasyConnect] WiFi: %s\n", EASY_CONNECT_WIFI_TYPE);
337+
}
338+
return &wifi;
339+
#else
340+
if (log_messages) {
341+
printf("[EasyConnect] ERROR - Wifi not in use, can not return WifiInterface.\n");
342+
}
343+
return NULL;
344+
#endif
345+
}

easy-connect.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,20 @@ NetworkInterface* easy_connect(bool log_messages = false);
9898
NetworkInterface* easy_connect(bool log_messages,
9999
char* WiFiSSID,
100100
char* WiFiPassword);
101+
102+
/* \brief easy_get_netif - easy_connect function to get pointer to network interface w/o connect it.
103+
You might need this for example getting the WiFi interface, then doing a scan
104+
and then connecting to one of the SSIDs found with a password end user supplies.
105+
* IN: bool log_messages print out diagnostics or not.
106+
*/
107+
108+
NetworkInterface* easy_get_netif(bool log_messages);
109+
/* \brief easy_get_wifi - easy_connect function to get pointer to Wifi interface
110+
* without connecting to it. You would want this 1st so that
111+
* you can scan the APNs, choose the right one and then connect.
112+
*
113+
* IN: bool log_messages print out diagnostics or not.
114+
*/
115+
WiFiInterface* easy_get_wifi(bool log_messages);
116+
101117
#endif // __EASY_CONNECT_H__

0 commit comments

Comments
 (0)