Skip to content

Commit 9f857ba

Browse files
committed
Watchdog-aware WiFi
Added wdt_reset to long-running operations in the WiFi library
1 parent 3397dac commit 9f857ba

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

libraries/WiFi/WiFiClient.cpp

+25-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ extern "C" {
1111
#include "WiFiServer.h"
1212
#include "server_drv.h"
1313

14+
#ifdef VERILITE_WDT_MODS
15+
// watchdog
16+
#include <avr/wdt.h>
17+
#endif
1418

1519
uint16_t WiFiClient::_srcport = 1024;
1620

@@ -39,8 +43,12 @@ int WiFiClient::connect(IPAddress ip, uint16_t port) {
3943
unsigned long start = millis();
4044

4145
// wait 4 second for the connection to close
42-
while (!connected() && millis() - start < 10000)
43-
delay(1);
46+
while (!connected() && millis() - start < 10000) {
47+
delay(1);
48+
#ifdef VERILITE_WDT_MODS
49+
wdt_reset(); // watchdog reset
50+
#endif
51+
}
4452

4553
if (!connected())
4654
{
@@ -119,8 +127,12 @@ int WiFiClient::peek() {
119127
}
120128

121129
void WiFiClient::flush() {
122-
while (available())
123-
read();
130+
while (available()) {
131+
#ifdef VERILITE_WDT_MODS
132+
wdt_reset(); // watchdog reset
133+
#endif
134+
read();
135+
}
124136
}
125137

126138
void WiFiClient::stop() {
@@ -133,8 +145,12 @@ void WiFiClient::stop() {
133145

134146
int count = 0;
135147
// wait maximum 5 secs for the connection to close
136-
while (status() != CLOSED && ++count < 50)
137-
delay(100);
148+
while (status() != CLOSED && ++count < 50) {
149+
delay(100);
150+
#ifdef VERILITE_WDT_MODS
151+
wdt_reset(); // watchdog reset
152+
#endif
153+
}
138154

139155
_sock = 255;
140156
}
@@ -157,6 +173,9 @@ uint8_t WiFiClient::status() {
157173
if (_sock == 255) {
158174
return CLOSED;
159175
} else {
176+
#ifdef VERILITE_WDT_MODS
177+
wdt_reset(); // watchdog reset
178+
#endif
160179
return ServerDrv::getClientState(_sock);
161180
}
162181
}

0 commit comments

Comments
 (0)