Skip to content

Commit

Permalink
avoid sending null through live data websockets
Browse files Browse the repository at this point in the history
on the "main" live data websocket this can happen if no
OnBattery-specific data is available to sent but the empty
JSON document is still sent, which trips the web application.

publishing null in the battery live data websocket also trips the web
application, which rightfully assumes a valid object if data is received
through the websocket.
  • Loading branch information
schlimmchen committed Mar 23, 2024
1 parent 13e4205 commit d935283
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/WebApi_ws_battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ void WebApiWsBatteryLiveClass::sendDataTaskCb()
JsonVariant var = root;
generateJsonResponse(var);

// battery provider does not generate a card, e.g., MQTT provider
if (root.isNull()) { return; }

String buffer;
serializeJson(root, buffer);

Expand Down
2 changes: 2 additions & 0 deletions src/WebApi_ws_live.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ void WebApiWsLiveClass::sendOnBatteryStats()
if (all) { _lastPublishOnBatteryFull = millis(); }
generateOnBatteryJsonResponse(var, all);

if (root.isNull()) { return; }

String buffer;
serializeJson(root, buffer);

Expand Down

0 comments on commit d935283

Please sign in to comment.