From 5c8d4b29c11a6f771c2ccfa83b7212b293a1e73f Mon Sep 17 00:00:00 2001 From: Ewoud Date: Tue, 23 Jan 2024 15:30:29 +0100 Subject: [PATCH] Tweaks: ws client queuelength check for lossy calls --- src/App/AppModPreview.h | 6 ++++-- src/Sys/SysModModel.cpp | 2 +- src/Sys/SysModPins.cpp | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/App/AppModPreview.h b/src/App/AppModPreview.h index 5bc221bf..385966d7 100644 --- a/src/App/AppModPreview.h +++ b/src/App/AppModPreview.h @@ -30,8 +30,10 @@ class AppModPreview:public SysModule { // web->addResponse(var["id"], "comment", "Click to enlarge"); }, nullptr, [](JsonObject var, uint8_t rowNr) { //loopFun - xSemaphoreTake(web->wsMutex, portMAX_DELAY); + + web->wsSendBytesCounter++; + SysModWeb::ws->cleanupClients(); uint8_t* buffer; @@ -56,7 +58,7 @@ class AppModPreview:public SysModule { var["interval"] = max(ledsV.nrOfLedsP * SysModWeb::ws->count()/200, 16U)*10; //interval in ms * 10, not too fast //from cs to ms for (auto client:SysModWeb::ws->getClients()) { - // if (client->status() == WS_CONNECTED && !client->queueIsFull() && client->queueLength()<=3) //lossy + if (client->status() == WS_CONNECTED && !client->queueIsFull() && client->queueLength() <= WS_MAX_QUEUED_MESSAGES / 2) //lossy client->binary(wsBuf); // else { // web->clientsChanged = true; tbd: changed also if full status changes diff --git a/src/Sys/SysModModel.cpp b/src/Sys/SysModModel.cpp index 3559f15a..a9d2c31d 100644 --- a/src/Sys/SysModModel.cpp +++ b/src/Sys/SysModModel.cpp @@ -190,7 +190,7 @@ void SysModModel::setValueLossy(const char * id, const char * format, ...) { bool isOk = true; for (auto client:SysModWeb::ws->getClients()) { - if (client->status() != WS_CONNECTED || client->queueIsFull() || client->queueLength()>3) //lossy + if (client->status() != WS_CONNECTED || client->queueIsFull() || client->queueLength()>WS_MAX_QUEUED_MESSAGES/2) //lossy isOk = false; } if (isOk) diff --git a/src/Sys/SysModPins.cpp b/src/Sys/SysModPins.cpp index 1e5d7358..73fbdbd6 100644 --- a/src/Sys/SysModPins.cpp +++ b/src/Sys/SysModPins.cpp @@ -72,6 +72,8 @@ void SysModPins::setup() { xSemaphoreTake(web->wsMutex, portMAX_DELAY); + web->wsSendBytesCounter++; + SysModWeb::ws->cleanupClients(); uint8_t* buffer; @@ -96,7 +98,7 @@ void SysModPins::setup() { var["interval"] = 10*10*10; //every 10 sec from cs to ms for (auto client:SysModWeb::ws->getClients()) { - // if (client->status() == WS_CONNECTED && !client->queueIsFull() && client->queueLength()<=3) //lossy + if (client->status() == WS_CONNECTED && !client->queueIsFull() && client->queueLength() <= WS_MAX_QUEUED_MESSAGES / 2) //lossy client->binary(wsBuf); // else { // web->clientsChanged = true; tbd: changed also if full status changes