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

API to get network and WiFi interfaces w/o connecting #61

Merged
merged 1 commit into from
Dec 19, 2017
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
55 changes: 54 additions & 1 deletion easy-connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ char* _password = NULL;
/* \brief print_MAC - print_MAC - helper function to print out MAC address
* in: network_interface - pointer to network i/f
* bool log-messages print out logs or not
* MAC address is print, if it can be acquired & log_messages is true.
* MAC address is printed, if it can be acquired & log_messages is true.
*
*/
void print_MAC(NetworkInterface* network_interface, bool log_messages) {
Expand All @@ -139,6 +139,7 @@ void print_MAC(NetworkInterface* network_interface, bool log_messages) {

/* \brief easy_connect easy_connect() function to connect the pre-defined network bearer,
* config done via mbed_app.json (see README.md for details).
*
* IN: bool log_messages print out diagnostics or not.
*/
NetworkInterface* easy_connect(bool log_messages) {
Expand Down Expand Up @@ -290,3 +291,55 @@ NetworkInterface* easy_connect(bool log_messages,
#endif // EASY_CONNECT_WIFI
return easy_connect(log_messages);
}

/* \brief easy_get_netif - easy_connect function to get pointer to network interface
* without connecting to it.
*
* IN: bool log_messages print out diagnostics or not.
*/
NetworkInterface* easy_get_netif(bool log_messages) {
#if defined (EASY_CONNECT_WIFI)
if (log_messages) {
printf("[EasyConnect] WiFi: %s\n", EASY_CONNECT_WIFI_TYPE);
}
return &wifi;

#elif MBED_CONF_APP_NETWORK_INTERFACE == ETHERNET
if (log_messages) {
printf("[EasyConnect] Ethernet\n");
}
return ð

#elif defined (EASY_CONNECT_MESH)
if (log_messages) {
printf("[EasyConnect] Mesh : %s\n", EASY_CONNECT_MESH_TYPE);
}
return &mesh;

#elif MBED_CONF_APP_NETWORK_INTERFACE == CELLULAR_ONBOARD
if (log_messages) {
printf("[EasyConnect] Cellular\n");
}
return &cellular;
#endif
}

/* \brief easy_get_wifi - easy_connect function to get pointer to Wifi interface
* without connecting to it. You would want this 1st so that
* you can scan the APNs, choose the right one and then connect.
*
* IN: bool log_messages print out diagnostics or not.
*/
WiFiInterface* easy_get_wifi(bool log_messages) {
#if defined (EASY_CONNECT_WIFI)
if (log_messages) {
printf("[EasyConnect] WiFi: %s\n", EASY_CONNECT_WIFI_TYPE);
}
return &wifi;
#else
if (log_messages) {
printf("[EasyConnect] ERROR - Wifi not in use, can not return WifiInterface.\n");
}
return NULL;
#endif
}
16 changes: 16 additions & 0 deletions easy-connect.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,20 @@ NetworkInterface* easy_connect(bool log_messages = false);
NetworkInterface* easy_connect(bool log_messages,
char* WiFiSSID,
char* WiFiPassword);

/* \brief easy_get_netif - easy_connect function to get pointer to network interface w/o connect it.
You might need this for example getting the WiFi interface, then doing a scan
and then connecting to one of the SSIDs found with a password end user supplies.
* IN: bool log_messages print out diagnostics or not.
*/

NetworkInterface* easy_get_netif(bool log_messages);
/* \brief easy_get_wifi - easy_connect function to get pointer to Wifi interface
* without connecting to it. You would want this 1st so that
* you can scan the APNs, choose the right one and then connect.
*
* IN: bool log_messages print out diagnostics or not.
*/
WiFiInterface* easy_get_wifi(bool log_messages);

#endif // __EASY_CONNECT_H__