Skip to content

Commit e288ad9

Browse files
re-connect Wifi if disconnects.
1 parent ed02231 commit e288ad9

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

examples/DimmableSmartLight/DimmableSmartLight.ino

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,17 @@ void loop_fauxmo() {
325325
// Therefore, we have to manually poll for UDP packets
326326
fauxmo.handle();
327327

328-
// This is a sample code to output free heap every 5 seconds
329-
// This is a cheap way to detect memory leaks
328+
// Check Wifi connection and memory leaks
330329
static unsigned long last = millis();
331330
if (millis() - last > 5000) {
332-
last = millis();
333-
DBG("[MAIN] Free heap: %d bytes\n", MCU.getFreeHeap());
331+
last = millis();
332+
DBG("[MAIN] Free heap: %d bytes\n", MCU.getFreeHeap());
333+
if (WiFi.status() != WL_CONNECTED) {
334+
WiFi.disconnect();
335+
DBG("[MAIN] Wifi disconnected. Rebooting\n");
336+
delay(100);
337+
MCU.restart();
338+
}
334339
}
335340

336341
outputControl();

examples/SmartLight/SmartLight.ino

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,17 @@ void loop_fauxmo() {
303303
// Therefore, we have to manually poll for UDP packets
304304
fauxmo.handle();
305305

306-
// This is a sample code to output free heap every 5 seconds
307-
// This is a cheap way to detect memory leaks
306+
// Check Wifi connection and memory leaks
308307
static unsigned long last = millis();
309308
if (millis() - last > 5000) {
310-
last = millis();
311-
DBG("[MAIN] Free heap: %d bytes\n", MCU.getFreeHeap());
309+
last = millis();
310+
DBG("[MAIN] Free heap: %d bytes\n", MCU.getFreeHeap());
311+
if (WiFi.status() != WL_CONNECTED) {
312+
WiFi.disconnect();
313+
DBG("[MAIN] Wifi disconnected. Rebooting\n");
314+
delay(100);
315+
MCU.restart();
316+
}
312317
}
313318

314319
outputControl();

0 commit comments

Comments
 (0)