-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TB] Unable to de-serialize received json data with error (DeserializationError::NoMemory) #216
Comments
The aforementioned error, Either there is not enough heap memory to use the const size_t document_size = JSON_OBJECT_SIZE(Helper::getOccurences(reinterpret_cast<char *>(payload), ':'));
TBJsonDocument jsonBuffer(document_size);
if (jsonBuffer.capacity() != document_size) {
Logger::printfln("Could not allocate required size (%u) for JsonDocument, allocated only (%u). Ensure there is enough heap memory left", document_size, jsonBuffer.capacity());
return;
}
....
#if THINGSBOARD_ENABLE_DEBUG
Logger::printfln("Allocated internal JsonDocument for MQTT server response with size (%u)", document_size);
#endif // THINGSBOARD_ENABLE_DEBUG The additional log message, prints the actual size of the JsonDocument, because the only remaining option is that the internal allocated JsonDocument size is to small to hold the actual data, could be the case if the For now if you could add the above code and retry the same behaviour and send the new log messages that would help a lot with debugging this issue thanks. |
Mathew hi: I am using the 8mB ESP32, and the compile stats are: can run over the code and see what might be now corrupting the core when this loads, I have not seen that before.. this just has the 2 RPC, can you confirm the lib versions, as I updated the StreamUtil manually from 1.7 to 1.9 // getting serialize error 9 PM Monday // build RPC_Subs_test_aug27a tuesday AM // ********************* start up events ********************** #include <ThingsBoard.h> // 0.13.0 WiFiClient espClient; // Enable verbose debugging output // WiFi credentials // ThingsBoard credentials // Forward declaration of RPC functions // Define RPC callbacks as a global variable }; bool TB_connected = false; void setup() { // Connect to ThingsBoard // Initial RPC subscription void reconnect() { // Reconnect to ThingsBoard void loop() { // Heartbeat check void heartbeatCheck() { if (!TB_connected) { // Subscribe to RPC if not subscribed void subscribeToRPCs() { const RPC_Callback* begin = callbacks.data(); if (!tb.RPC_Subscribe(begin, end)) { // Simplified RPC handlers void processPower(const JsonVariantConst& data, JsonDocument& response) { // Implement your power control logic here response["success"] = true; // Check if the data is a JsonObject // Get the size needed for the JSON object in the document // Allocate the JsonDocument with the calculated size // Log the allocated size for debugging // Deserialize the incoming data into the jsonBuffer // Assuming that the reboot command does not need any specific data delay(1000); // Delay for debugging, remove in production |
You need to adjust the Furthermore when you use RPC with Dynamic mode, the Additionally I'm not sure why you are copying the JsonDocument in the Because setting the response is useless anyway, because it will never be sent if you restart the device before the method finished executing. Because the response data is only sent after the method has finished executing. |
Mathew, hi, I have gone back to basics and refined the set up. and reverted back to non dynamic operations: thats solved the memory and Unable to de-serialize json etc.. Arduino_MQTT_Client mqttClient(espClient); the code example was simply a strip down from the mainstream code, to test and reasonably evaluate. So, the function to reboot was simply a place holder and like the others not final operations. For example, the reboot function includes resolving the cause of the reboot, Put to the eeprom and the doing the reboot itself. So when it restarts the eeprom has the reason stored. and that is sent at start up... etc. The mainstream code is around 15K lines and have a lot of things going on. Now including ChatGPT and building Dynamic Prompts, where the sensor constructs Air Quality messages for things like Pollen detection (Indoor readings from the Sensor itself, and from Polling EPA and Government formal Pollen sensing and then used "descriptions" fear, anxiety, gen types, and others to send out social media messages to the user and carers etc.) It becomes very interactive. So, a strip down is necessary to isolate issues. I will close the issue now, as the RPC is largely OK, and later experiment with options. As I am getting a more refined understanding and impacts. Testing looks ok now; I will post on my AWS - OTA in a few days. Thanks again.. cheers. |
I have made the changes as in the readme, but still get the de-serialize error, the RPC is currently not firing the function.
the debug shows:
14:50:44.234 -> Subscribed to RPC methods
14:51:00.405 -> [TB] Received data from server over topic (v1/devices/me/rpc/request/387)
14:51:00.405 -> [TB] Unable to de-serialize received json data with error (DeserializationError::NoMemory)
the TB Log shows
{
"entityId": "6c5e7550-4327-11ef-86ad-337f063d8218",
"oneWay": true,
"method": "power",
"params": "true"
}
I currently have:
// ********************* start up events **********************
#define THINGSBOARD_ENABLE_DYNAMIC 1
#define THINGSBOARD_ENABLE_PROGMEM 0
#define THINGSBOARD_JSON_BUFFER_SIZE 256
#define THINGSBOARD_ENABLE_DEBUG 1
#define THINGSBOARD_ENABLE_STREAM_UTILS 1
#include <ThingsBoard.h> // 13.0
#include <ArduinoJson.h> // 7.1.0
#include <Arduino_MQTT_Client.h> // 1.7.3
#include <StreamUtils.h> // 1.9
#include <WiFi.h>
#include <HTTPClient.h>
WiFiClient espClient;
Arduino_MQTT_Client mqttClient(espClient);
ThingsBoard tb(mqttClient);
// Enable verbose debugging output
#define DEBUG_LEVEL_TLS_ERROR
is it related to the Lib versions?
not sure if its connected, i updated StreamUtils to 1.9 and now I get a
16:55:04.868 -> ELF file SHA256: a9b6c20fd1abb1d5
16:55:04.868 ->
16:55:04.868 -> E (337) esp_core_dump_flash: Core dump flash config is corrupted! CRC=0x7bd5c66f instead of 0x0
16:55:04.868 -> Rebooting...
clearly an error. I can recover the core and reprogram.
any suggestions to change / remove?
thanks in advance..
The text was updated successfully, but these errors were encountered: