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

serialize json data issue #10164

Closed
Cube-Controls opened this issue Feb 10, 2024 · 8 comments
Closed

serialize json data issue #10164

Cube-Controls opened this issue Feb 10, 2024 · 8 comments
Assignees
Labels
question generic question

Comments

@Cube-Controls
Copy link

Component

  • Generic

Description
Frist time testing TB with ESP32, I'm getting "[TB] Unable to serialize json data" on any tb.sendTelemetryData or tb.sendAttributeData.
tb.sendTelemetryJson is working.

Environment

  • OS: Windows 11
  • ThingsBoard: 0.12.2 Arduino
@Cube-Controls Cube-Controls added the question generic question label Feb 10, 2024
@Cube-Controls Cube-Controls changed the title Your title here serialize json data issue Feb 10, 2024
@gittimotap
Copy link

Hi. I'm having the exact same issue. I'm using Firebeetle 2 ESP32 and no matter which code example I take, once I post anything to the server, I get the response "[TB] Unable to serialize json data". I'm able to use the API via command line using MQTT or CURL with no issues. For reproducing you can use demo.thingsboard.io and just send data, it will answer with the same error.

@Cube-Controls
Copy link
Author

I think problem is in Arduino SDK , something with functions that create JSON.
tb.sendTelemetryJson function is working ok , because you can create JSON manualy before sending.

Functions that require SDK to create JSON don't work.
Maybe this is wrong repository I posted question, probably should be in [thingsboard-client-sdk] repository.

@gittimotap
Copy link

I'm using 2 different boards, https://wiki.dfrobot.com/SKU_DFR0868_Beetle_ESP32_C3 and https://wiki.dfrobot.com/FireBeetle_Board_ESP32_E_SKU_DFR0654, both give me the same issue when posting anything to the server. Do you mean this https://github.com/espressif/arduino-esp32 for Arduino SDK?

@gittimotap
Copy link

Seems like the issue is with ArduinoJSON library, 6.21.5 works, I've opened a bug for this

@Cube-Controls
Copy link
Author

No there is SDK from thingsboard https://github.com/thingsboard/thingsboard-client-sdk that is used for ESP32.

tb.sendAttributeData and tb.sendTelemetryData are implemented there and it looks that problem is with serialization of data to JSON before sending to thingsboard server. It could be problem and with one of the libraries that are used for json serialization.

This is not working and causing "[TB] Unable to serialize json data"


    tb.sendTelemetryData("temperature", random(10, 20));
    tb.sendAttributeData("rssi", WiFi.RSSI());

If you serialize data in the code and send josn directly using tb.sendTelemetryJson then it is working.

void sendDataToThingsBoard(float temp, int hum) {
  String jsonData = "{\"temperature\":" + String(temp) + ", \"humidity\":" + String(hum) + "}";
  tb.sendTelemetryJson(jsonData.c_str());
  Serial.println("Data sent");
}

void sendAttributesToThingsBoard(void) {
  String jsonData = "{\"rsss\":" + String(1234) + ", \"test\":" + String(456) + "}";
  tb.sendAttributeJSON(jsonData.c_str());
  Serial.println("Attributes sent");
}

I just hoped someone already figured out this issue, I will try to debug to see what is going on.

@Cube-Controls
Copy link
Author

Cube-Controls commented Feb 12, 2024

Seems like the issue is with ArduinoJSON library, 6.21.5 works, I've opened a bug for this

I confirmed that, I will close this issue.

thingsboard/thingsboard-client-sdk#186 (comment)

@utkarshjosh
Copy link

Yes, downgrading from ^7~ to 6.21.5 really worked. Thanks A lot. 🥳

@gittimotap
Copy link

7.0.4 also works now

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

No branches or pull requests

4 participants