Skip to content

Commit 439a7d2

Browse files
committed
0.0.6-beta.1
1 parent f83984b commit 439a7d2

3 files changed

Lines changed: 67 additions & 4 deletions

File tree

‎platformio.ini‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ build_unflags =
3333
; ESP32 and S2, S3, C2, C3, C5, C6 (SDK > 5.x)
3434
; =========================================================
3535

36-
[end:esp32-enable-cdc]
36+
[env:esp32-enable-cdc]
3737
build_flags = -DARDUINO_USB_CDC_ON_BOOT=1 -DARDUINO_USB_MODE=1
3838

3939
[env:modern-esp]
@@ -45,7 +45,7 @@ framework = arduino
4545

4646
build_flags =
4747
${env.build_flags}
48-
-DCONFIG_ASYNC_TCP_STACK_SIZE=4096
48+
-DCONFIG_ASYNC_TCP_STACK_SIZE=5120
4949
-DUSE_ASYNC_WEBSERWER=1
5050

5151
lib_ignore =
@@ -105,7 +105,7 @@ lib_deps =
105105
https://github.com/hathach/tinyusb.git#0.20.0
106106
build_flags =
107107
${env:multi-esp32-led-strip.build_flags}
108-
${end:esp32-enable-cdc.build_flags}
108+
${env:esp32-enable-cdc.build_flags}
109109
-DUSE_SYNC_WEBSERWER=1
110110
"-DCFG_TUSB_CONFIG_FILE=\"${PROJECT_DIR}/include/esp32/tusb_config.h\""
111111

@@ -132,6 +132,8 @@ board = esp32-s3-devkitc-1
132132
build_flags =
133133
${env:multi-esp32-led-strip.build_flags}
134134
${env:esp32-enable-cdc.build_flags}
135+
-DCONFIG_ASYNC_TCP_STACK_SIZE=8192
136+
build_unflags = -DCONFIG_ASYNC_TCP_STACK_SIZE=5120
135137

136138
; ========
137139
; ESP32-C2

‎src/main.cpp‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <ETH.h>
3939
#endif
4040
#include <Update.h>
41+
#include <atomic>
4142
#elif defined(ARDUINO_ARCH_RP2040) || defined(ARDUINO_ARCH_RP2350)
4243
#include <WiFi.h>
4344
#include <LEAmDNS.h>
@@ -90,6 +91,46 @@ bool isAPMode() {
9091
return inAPMode;
9192
}
9293

94+
#if defined(ARDUINO_ARCH_ESP32)
95+
namespace WifiRecovery{
96+
constexpr unsigned long WIFI_RECOVERY_DELAY = 10000UL;
97+
98+
enum class WifiEvent : uint8_t { NONE = 0, ASSOC_LEAVE, STA_CONNECTED};
99+
std::atomic<WifiEvent> wifiEvent{WifiEvent::NONE};
100+
101+
bool wifiRecoveryPending = false;
102+
unsigned long wifiRecoveryStarted = 0UL;
103+
104+
void processWiFiRecovery() {
105+
switch (wifiEvent.exchange(WifiEvent::NONE, std::memory_order_relaxed)) {
106+
case WifiEvent::ASSOC_LEAVE:
107+
if (!wifiRecoveryPending) {
108+
wifiRecoveryPending = true;
109+
wifiRecoveryStarted = millis();
110+
Log::SERIAL_LOG("[WiFi] ASSOC_LEAVE detected, recovery watchdog armed");
111+
}
112+
break;
113+
114+
case WifiEvent::STA_CONNECTED:
115+
wifiRecoveryPending = false;
116+
Log::SERIAL_LOG("[WiFi] STA_CONNECTED detected, disabling recovery watchdog");
117+
break;
118+
119+
default:
120+
break;
121+
}
122+
123+
if (wifiRecoveryPending && millis() - wifiRecoveryStarted >= WIFI_RECOVERY_DELAY) {
124+
wifiRecoveryPending = false;
125+
126+
if (WiFi.status() != WL_CONNECTED) {
127+
Log::SERIAL_LOG("[WiFi] Recovery timeout, reconnect request: ", WiFi.reconnect() ? "accepted" : "failed");
128+
}
129+
}
130+
}
131+
}
132+
#endif
133+
93134
void setup() {
94135
#if defined(ARDUINO_ARCH_ESP32)
95136
LittleFS.begin(true);
@@ -156,6 +197,21 @@ void setup() {
156197
{
157198
Log::SERIAL_LOG("Connected → ", WiFi.localIP());
158199
}
200+
201+
#if defined(ARDUINO_ARCH_ESP32)
202+
// register recovery procedure if not in AP/ethernet mode
203+
if (!inAPMode) {
204+
WiFi.onEvent([](WiFiEvent_t event, WiFiEventInfo_t info) {
205+
if (event == ARDUINO_EVENT_WIFI_STA_DISCONNECTED && info.wifi_sta_disconnected.reason == WIFI_REASON_ASSOC_LEAVE) {
206+
WifiRecovery::wifiEvent.store(WifiRecovery::WifiEvent::ASSOC_LEAVE, std::memory_order_relaxed);
207+
}
208+
else if (event == ARDUINO_EVENT_WIFI_STA_CONNECTED) {
209+
WifiRecovery::wifiEvent.store(WifiRecovery::WifiEvent::STA_CONNECTED, std::memory_order_relaxed);
210+
}
211+
});
212+
Log::SERIAL_LOG("Registered recovery procedure");
213+
}
214+
#endif
159215
}
160216

161217
if (!inAPMode) {
@@ -206,6 +262,11 @@ void loop()
206262
if (!inAPMode) {
207263
MDNS.update();
208264
}
265+
#elif defined(ARDUINO_ARCH_ESP32)
266+
if (!inAPMode && !hasEthernet) {
267+
// wifi recovery routine
268+
WifiRecovery::processWiFiRecovery();
269+
}
209270
#endif
210271

211272

‎version‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.5
1+
0.0.6-beta.1

0 commit comments

Comments
 (0)