Prevent empty HASS auto discovery topics if memory allocation fails

This commit is contained in:
Thomas Basler
2024-01-04 14:09:58 +01:00
parent 4053e31a5e
commit ca18d2c841
3 changed files with 37 additions and 0 deletions

View File

@@ -5,6 +5,7 @@
#include "Utils.h"
#include "Display_Graphic.h"
#include "Led_Single.h"
#include "MessageOutput.h"
#include <Esp.h>
uint32_t Utils::getChipId()
@@ -65,3 +66,13 @@ void Utils::restartDtu()
yield();
ESP.restart();
}
bool Utils::checkJsonAlloc(const DynamicJsonDocument& doc, const char* function, const uint16_t line)
{
if (doc.capacity() == 0) {
MessageOutput.printf("Alloc failed: %s, %d\r\n", function, line);
return false;
}
return true;
}