implement and use Utils::checkJsonOverflow()
this method calls the overflowed() method on the respective DynamicJsonDocument and prints a respective message if not all data could be added to the DynamicJsonDocument.
This commit is contained in:
parent
1fb2d4262e
commit
8bfb5c6523
@ -11,5 +11,6 @@ public:
|
||||
static int getTimezoneOffset();
|
||||
static void restartDtu();
|
||||
static bool checkJsonAlloc(const DynamicJsonDocument& doc, const char* function, const uint16_t line);
|
||||
static bool checkJsonOverflow(const DynamicJsonDocument& doc, const char* function, const uint16_t line);
|
||||
static void removeAllFiles();
|
||||
};
|
||||
|
||||
@ -151,6 +151,8 @@ void MqttHandleVedirectHassClass::publishSensor(const char *caption, const char
|
||||
root["stat_cla"] = stateClass;
|
||||
}
|
||||
|
||||
if (Utils::checkJsonOverflow(root, __FUNCTION__, __LINE__)) { return; }
|
||||
|
||||
char buffer[512];
|
||||
serializeJson(root, buffer);
|
||||
publish(configTopic, buffer);
|
||||
@ -195,6 +197,8 @@ void MqttHandleVedirectHassClass::publishBinarySensor(const char *caption, const
|
||||
JsonObject deviceObj = root.createNestedObject("dev");
|
||||
createDeviceInfo(deviceObj, spMpptData);
|
||||
|
||||
if (Utils::checkJsonOverflow(root, __FUNCTION__, __LINE__)) { return; }
|
||||
|
||||
char buffer[512];
|
||||
serializeJson(root, buffer);
|
||||
publish(configTopic, buffer);
|
||||
|
||||
@ -173,6 +173,8 @@ void MqttHandleBatteryHassClass::publishSensor(const char* caption, const char*
|
||||
root["stat_cla"] = stateClass;
|
||||
}
|
||||
|
||||
if (Utils::checkJsonOverflow(root, __FUNCTION__, __LINE__)) { return; }
|
||||
|
||||
char buffer[512];
|
||||
serializeJson(root, buffer);
|
||||
publish(configTopic, buffer);
|
||||
@ -216,6 +218,8 @@ void MqttHandleBatteryHassClass::publishBinarySensor(const char* caption, const
|
||||
JsonObject deviceObj = root.createNestedObject("dev");
|
||||
createDeviceInfo(deviceObj);
|
||||
|
||||
if (Utils::checkJsonOverflow(root, __FUNCTION__, __LINE__)) { return; }
|
||||
|
||||
char buffer[512];
|
||||
serializeJson(root, buffer);
|
||||
publish(configTopic, buffer);
|
||||
|
||||
@ -133,6 +133,8 @@ void MqttHandlePowerLimiterHassClass::publishSelect(
|
||||
JsonObject deviceObj = root.createNestedObject("dev");
|
||||
createDeviceInfo(deviceObj);
|
||||
|
||||
if (Utils::checkJsonOverflow(root, __FUNCTION__, __LINE__)) { return; }
|
||||
|
||||
String buffer;
|
||||
serializeJson(root, buffer);
|
||||
publish(configTopic, buffer);
|
||||
@ -179,6 +181,8 @@ void MqttHandlePowerLimiterHassClass::publishNumber(
|
||||
JsonObject deviceObj = root.createNestedObject("dev");
|
||||
createDeviceInfo(deviceObj);
|
||||
|
||||
if (Utils::checkJsonOverflow(root, __FUNCTION__, __LINE__)) { return; }
|
||||
|
||||
String buffer;
|
||||
serializeJson(root, buffer);
|
||||
publish(configTopic, buffer);
|
||||
|
||||
@ -79,6 +79,16 @@ bool Utils::checkJsonAlloc(const DynamicJsonDocument& doc, const char* function,
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Utils::checkJsonOverflow(const DynamicJsonDocument& doc, const char* function, const uint16_t line)
|
||||
{
|
||||
if (doc.overflowed()) {
|
||||
MessageOutput.printf("DynamicJsonDocument overflowed: %s, %d\r\n", function, line);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// @brief Remove all files but the PINMAPPING_FILENAME
|
||||
void Utils::removeAllFiles()
|
||||
{
|
||||
|
||||
@ -64,6 +64,8 @@ void WebApiWsHuaweiLiveClass::sendDataTaskCb()
|
||||
JsonVariant var = root;
|
||||
generateJsonResponse(var);
|
||||
|
||||
if (Utils::checkJsonOverflow(root, __FUNCTION__, __LINE__)) { return; }
|
||||
|
||||
String buffer;
|
||||
serializeJson(root, buffer);
|
||||
|
||||
|
||||
@ -67,6 +67,8 @@ void WebApiWsBatteryLiveClass::sendDataTaskCb()
|
||||
JsonVariant var = root;
|
||||
generateJsonResponse(var);
|
||||
|
||||
if (Utils::checkJsonOverflow(root, __FUNCTION__, __LINE__)) { return; }
|
||||
|
||||
// battery provider does not generate a card, e.g., MQTT provider
|
||||
if (root.isNull()) { return; }
|
||||
|
||||
|
||||
@ -123,6 +123,8 @@ void WebApiWsLiveClass::sendOnBatteryStats()
|
||||
|
||||
if (root.isNull()) { return; }
|
||||
|
||||
if (Utils::checkJsonOverflow(root, __FUNCTION__, __LINE__)) { return; }
|
||||
|
||||
String buffer;
|
||||
serializeJson(root, buffer);
|
||||
|
||||
|
||||
@ -91,6 +91,8 @@ void WebApiWsVedirectLiveClass::sendDataTaskCb()
|
||||
JsonVariant var = root;
|
||||
generateJsonResponse(var, fullUpdate);
|
||||
|
||||
if (Utils::checkJsonOverflow(root, __FUNCTION__, __LINE__)) { return; }
|
||||
|
||||
String buffer;
|
||||
serializeJson(root, buffer);
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user