Skip to content

Commit 47fe7ce

Browse files
sweidingeroz-agent
andauthored
fix: move WiFi handling after BLE command queue processing (#30)
In v1.6, handleWiFiServer() and the WiFi reconnection check were moved to the top of loop(), before BLE command/response queue processing. This can cause BLE commands to sit unprocessed in the queue when handleWiFiServer() blocks or takes a slow path, resulting in BLE timeouts for clients (Home Assistant integration, py-opendisplay). Observed symptoms: - BLE READ CONFIG commands queued but never processed - 'ESP32: Command queued for processing' appears in serial log but 'ESP32: Processing queued command' never follows - Home Assistant integration fails with 'ble_timeout' during device interrogation - py-opendisplay image uploads timeout after 10s This commit moves WiFi handling back to after the BLE command queue drain and response notification loop, restoring the v1.3 execution order where BLE is always serviced first. WiFi functionality is preserved — only the ordering within the loop iteration changes. Co-authored-by: Oz <oz-agent@warp.dev>
1 parent 48d9255 commit 47fe7ce

1 file changed

Lines changed: 18 additions & 16 deletions

File tree

‎src/main.cpp‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,6 @@ void setup() {
113113
void loop() {
114114
processLedFlash();
115115
#ifdef TARGET_ESP32
116-
handleWiFiServer();
117-
static uint32_t lastWiFiCheck = 0;
118-
if (wifiInitialized && (millis() - lastWiFiCheck > 10000)) {
119-
lastWiFiCheck = millis();
120-
if (WiFi.status() != WL_CONNECTED && wifiConnected) {
121-
writeSerial("WiFi connection lost (status: " + String(WiFi.status()) + ")");
122-
wifiConnected = false;
123-
if (wifiServerConnected) {
124-
disconnectWiFiServer();
125-
}
126-
} else if (WiFi.status() == WL_CONNECTED && !wifiConnected) {
127-
writeSerial("WiFi reconnected (IP: " + WiFi.localIP().toString() + ")");
128-
wifiConnected = true;
129-
restartWiFiLanAfterReconnect();
130-
}
131-
}
132116
if (woke_from_deep_sleep && advertising_timeout_active) {
133117
if (pServer && pServer->getConnectedCount() > 0) {
134118
writeSerial("BLE connection established - switching to full mode");
@@ -188,6 +172,24 @@ void loop() {
188172
cleanupDirectWriteState(true);
189173
}
190174
}
175+
// WiFi handling runs after BLE queue processing to avoid blocking
176+
// BLE command responses (moved from top of loop in v1.6 fix).
177+
handleWiFiServer();
178+
static uint32_t lastWiFiCheck = 0;
179+
if (wifiInitialized && (millis() - lastWiFiCheck > 10000)) {
180+
lastWiFiCheck = millis();
181+
if (WiFi.status() != WL_CONNECTED && wifiConnected) {
182+
writeSerial("WiFi connection lost (status: " + String(WiFi.status()) + ")");
183+
wifiConnected = false;
184+
if (wifiServerConnected) {
185+
disconnectWiFiServer();
186+
}
187+
} else if (WiFi.status() == WL_CONNECTED && !wifiConnected) {
188+
writeSerial("WiFi reconnected (IP: " + WiFi.localIP().toString() + ")");
189+
wifiConnected = true;
190+
restartWiFiLanAfterReconnect();
191+
}
192+
}
191193
#ifdef TARGET_ESP32
192194
const bool wifiLanSession = wifiInitialized && wifiServerConnected && wifiClient.connected();
193195
#else

0 commit comments

Comments
 (0)