Skip to content

Commit 322e93c

Browse files
Fix: Show QR code only when WiFi is connected in Station mode
- Added WiFi.status() check before generating QR code - QR code only displayed when WL_CONNECTED - Periodic updates now clear QR code area if device disconnects - Prevents displaying outdated credentials when not connected - Improves user experience by showing accurate connection state Behavior: - Connected: Shows QR code with WiFi credentials - Disconnected: No QR code displayed (black area) - Reconnects: QR code reappears automatically Flash: 1,161,085 bytes (+48 bytes) RAM: 53,072 bytes (16.2%)
1 parent 4b261de commit 322e93c

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

lib/TFTDisplay/tft_display.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ static void tftDisplayTask(void* parameter) {
365365
break;
366366

367367
case TFT_MODE_STATION:
368-
// Full display update with QR code
368+
// Full display update with QR code (only if connected)
369369
clearTFT();
370370

371371
// Display mode indicator
@@ -374,8 +374,9 @@ static void tftDisplayTask(void* parameter) {
374374
tft->setCursor(TFT_INFO_X_OFFSET, TFT_MODE_Y_OFFSET);
375375
tft->print(" Station Mode");
376376

377-
// Create WiFi connection string for QR code
378-
{
377+
// Only show QR code if device is currently connected
378+
if (WiFi.status() == WL_CONNECTED) {
379+
// Create WiFi connection string for QR code
379380
String qrData = "WIFI:T:WPA;S:" + String(msg.data.station.ssid) +
380381
";P:" + String(msg.data.station.password) + ";;";
381382

@@ -424,8 +425,23 @@ static void tftDisplayTask(void* parameter) {
424425
Serial.println("🔄 AP Info updated periodically by task");
425426
}
426427
} else if (currentMode == TFT_MODE_STATION) {
427-
// Periodic Station info update
428+
// Periodic Station info update - check if still connected
428429
if ((currentTick - lastStationUpdate) >= STATION_UPDATE_INTERVAL) {
430+
// Check if WiFi is still connected
431+
if (WiFi.status() != WL_CONNECTED) {
432+
// Device disconnected - clear QR code area
433+
int moduleSize = 4;
434+
int qrSize = 25 * moduleSize;
435+
int offsetX = (TFT_WIDTH - qrSize) / 2;
436+
int offsetY = 5;
437+
int borderSize = 8;
438+
439+
// Clear QR code area (fill with black)
440+
tft->fillRect(offsetX - borderSize, offsetY - borderSize,
441+
qrSize + (borderSize * 2), qrSize + (borderSize * 2),
442+
ST77XX_BLACK);
443+
}
444+
429445
displayStationDetailsInternal(lastStationInfo);
430446
lastStationUpdate = currentTick;
431447
Serial.println("🔄 Station Info updated periodically by task");

0 commit comments

Comments
 (0)