From 55b1db4508af419cbe1d21f15120c338f174f3cb Mon Sep 17 00:00:00 2001 From: cjkas Date: Sun, 11 Oct 2026 22:23:11 +0200 Subject: [PATCH] fix: stop warning about late pings Home Assistant's aiohttp client only pings after 20s without a message from the device, so with memStatus every 30s pings arrive every 30-60s and every one was logged as late. The gap depends on our own traffic, not the link, so log pings at debug level and keep the time of the last one for the disconnect line. Co-Authored-By: Claude Opus 5.5 --- src/Sockets.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/Sockets.cpp b/src/Sockets.cpp index 0fb61c7..fdaa276 100644 --- a/src/Sockets.cpp +++ b/src/Sockets.cpp @@ -26,8 +26,6 @@ static uint32_t clientMap[MAX_WS_CLIENTS] = {0,0,0,0,0}; // client stayed and how far apart its pings arrived. static uint32_t connectedAt[MAX_WS_CLIENTS] = {0,0,0,0,0}; static uint32_t lastPing[MAX_WS_CLIENTS] = {0,0,0,0,0}; -#define PING_LATE_MS 25000 - static uint8_t mapClientId(uint32_t asyncId) { for(uint8_t i = 0; i < MAX_WS_CLIENTS; i++) if(clientMap[i] == asyncId) return i; @@ -238,14 +236,13 @@ void SocketEmitter::wsEvent(AsyncWebSocket *server, AsyncWebSocketClient *client break; case WS_EVT_PING: { - // Home Assistant pings every 20s and drops the socket when the pong is - // late, so only a late ping is worth a line; it points at a stalled - // network task or a lossy link. + // Home Assistant only pings after 20s without a message from us, so + // the gap depends on our own traffic and says nothing about the link. + // It is kept for the disconnect line. uint8_t slot = mapClientId(asyncId); if(slot != 255) { uint32_t now = millis(); - if(lastPing[slot] && now - lastPing[slot] > PING_LATE_MS) - ESP_LOGW(TAG, "Socket [%lu] late ping, %lums since the last", asyncId, (unsigned long)(now - lastPing[slot])); + if(lastPing[slot]) ESP_LOGD(TAG, "Socket [%lu] ping, %lums since the last", asyncId, (unsigned long)(now - lastPing[slot])); lastPing[slot] = now; } }