Skip to content

Commit ddfb0a8

Browse files
pennamfacchinm
authored andcommitted
Add status callback to detect WiFi disconnections
1 parent 00ebc50 commit ddfb0a8

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

libraries/WiFi/src/WiFi.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ int arduino::WiFiClass::begin(const char* ssid, const char* passphrase) {
1717
return 0;
1818
}
1919

20+
wifi_if->attach(&arduino::WiFiClass::statusCallback);
21+
2022
scanNetworks();
2123
// use scan result to populate security field
2224
if (!isVisible(ssid)) {
@@ -210,6 +212,15 @@ unsigned long arduino::WiFiClass::getTime() {
210212
return 0;
211213
}
212214

215+
void arduino::WiFiClass::statusCallback(nsapi_event_t status, intptr_t param)
216+
{
217+
if (((param == NSAPI_STATUS_DISCONNECTED) ||
218+
(param == NSAPI_STATUS_CONNECTING)) &&
219+
(WiFi.status() == WL_CONNECTED)) {
220+
WiFi._currentNetworkStatus = WL_CONNECTION_LOST;
221+
}
222+
}
223+
213224
#if defined(COMPONENT_4343W_FS)
214225

215226
#define WIFI_FIRMWARE_PATH "/wlan/4343WA1.BIN"

libraries/WiFi/src/WiFi.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ class WiFiClass : public MbedSocketClass {
209209
void ensureDefaultAPNetworkConfiguration();
210210
static void* handleAPEvents(whd_interface_t ifp, const whd_event_header_t* event_header, const uint8_t* event_data, void* handler_user_data);
211211
bool isVisible(const char* ssid);
212+
static void statusCallback(nsapi_event_t status, intptr_t param);
212213
};
213214

214215
}

0 commit comments

Comments
 (0)