Skip to content
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

Provision fails when Dynamic ThingsBoard usage #201

Closed
pablo18393 opened this issue May 14, 2024 · 6 comments · Fixed by #180
Closed

Provision fails when Dynamic ThingsBoard usage #201

pablo18393 opened this issue May 14, 2024 · 6 comments · Fixed by #180

Comments

@pablo18393
Copy link

When setting Dynamic ThingsBoard usage:

#define THINGSBOARD_ENABLE_DYNAMIC 1

provision fails with the following message:

[TB] Unable to de-serialize received json data with error (DeserializationError::NoMemory)

Tested with [email protected] and [email protected],
thingsboard version 12.2

Thank you in advance, have a nice day.

@MathewHDYT
Copy link
Contributor

Can you add logs to this section of the code https://github.com/thingsboard/thingsboard-client-sdk/blob/master/src/ThingsBoard.h#L1979.

Simply add

Serial.println(reinterpret_cast<char*>(payload));
Serial.printf("Allocated memory: %d should be enought to hold payload of size: %d", dataStructureMemoryUsage, length);

@pablo18393
Copy link
Author

Here is raw data:
Sending provisioning request
{"credentialsValue":"jKexqfuXSlqYs7ow7L8z","credentialsType":"ACCESS_TOKEN","status":"SUCCESS"}zi8t3pnqxdlipqz"}t��q�E
(ou��,���
x�9dD��eSЍ6w� ��S�'��
��i����,H�E9�a� ����j|ol$���@(v
��w�L��T��Qщ}nwS/ Rn�
Allocated memory: 48 should be enought to hold payload of size: 95[TB] Unable to de-serialize received json data with error (DeserializationError::NoMemory)

@MathewHDYT
Copy link
Contributor

MathewHDYT commented May 15, 2024

Weird 48 should be exactly enough to hold the received payload in the allocated JsonDocument. I even verified it with the Arduino JSON Assistant.

For now can you simply change this line https://github.com/thingsboard/thingsboard-client-sdk/blob/master/src/ThingsBoard.h#L1971. To use the received length arugment instead of the calcualted dataStructureMemoryUsage and retry it again.


Because the other error could really be that you do not have enough memory on the heap, which is rather unrealistic. But to test that as well you can call this method. Serial.println(ESP.getFreeHeap());. Simply add this before the aforementioned line as well.

@pablo18393
Copy link
Author

pablo18393 commented May 15, 2024

Hello,

  • used received length argument with no fix of the issue.
  • I have also tried to add a "0" at the end the of received payload, with no efects:
    memset(payload + length, 0, 1); // Set bytes from length to end of buffer to 0
  • Also I have plenty of free heap, I have an ESP32 with the provision example running only.
  • For the moment I am not using THINGSBOARD_ENABLE_DYNAMIC and I am increasing Default_Fields_Amt since I am sending telemetries all together in a JSON.

Let me know if I can help me something.
Thank you for your work, have a nice day.

@MathewHDYT
Copy link
Contributor

MathewHDYT commented May 15, 2024

If it is possible can you add this log call as well after the JsonDocument has been initatied call Serial.printf("Allocated capacity: %d", jsonBuffer.capacity());

If this is 0 then the error is probably that it attempts to use PSRAM to save the document but it cannot allocate that specifc type of memory.

If that is the case please add this on top of your main file before including anything. #define THINGSBOARD_ENABLE_PSRAM 0

@pablo18393
Copy link
Author

pablo18393 commented May 15, 2024

Hello,
Seems like memory allocation is OK, but issue is still triggered:
Allocated memory: 48
[TB] Unable to de-serialize received json data with error (DeserializationError::NoMemory)

Anyway I tried with #define THINGSBOARD_ENABLE_PSRAM 0 and somehow now it works. I don't know why but it does.

Thank you very much for your tips. I leave it to you if you want to close this issue.

Have a nice day.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants