-
Notifications
You must be signed in to change notification settings - Fork 64
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
Can't publish data with timestamp (ts) through gw_send_telemetry #38
Comments
It worked while using: |
Wow, I spent a lot of time resolving this. @zsamora Thank you, this is the solution. Array of dictionaries has to be used: |
Everything works fine if the timestamp is not included, but when I try to use the function from https://thingsboard.io/docs/reference/python-client-sdk/#using-gateway-apis it gives me an error in ThingsBoard platform logs (using
sudo journalctl -u thingsboard.service
)Example that works:
from time import time from tb_gateway_mqtt import TBGatewayMqttClient gateway = TBGatewayMqttClient("THINGSBOARD_PLATFORM_IP", 1883, "GATEWAY_ACCESS_TOKEN") gateway.connect() gateway.gw_send_telemetry("DEVICE_ID", {"telemetryKey": "telemetryValue"})
Example that doesn't work:
from time import time from tb_gateway_mqtt import TBGatewayMqttClient gateway = TBGatewayMqttClient("THINGSBOARD_PLATFORM_IP", 1883, "GATEWAY_ACCESS_TOKEN")<br /> gateway.connect() gateway.gw_send_telemetry("DEVICE_ID", {"ts": int(round(time()*1000)), "values": {"telemetryKey": "telemetryValue"}})
When gw_send_telemetry is called in the second example, it gives me this in logs:
Mar 01 20:06:01 ip-172-31-34-70 thingsboard.jar[1750750]: Exception in thread "MqttTransportContext-50-2" com.google.gson.JsonSyntaxException: Can't parse value: {"040100":{"ts":1677701139953,"testTelemetry":3}} Mar 01 20:06:01 ip-172-31-34-70 thingsboard.jar[1750750]: at org.thingsboard.server.transport.mqtt.session.GatewaySessionHandler$3.onSuccess(GatewaySessionHandler.java:353) Mar 01 20:06:01 ip-172-31-34-70 thingsboard.jar[1750750]: at org.thingsboard.server.transport.mqtt.session.GatewaySessionHandler$3.onSuccess(GatewaySessionHandler.java:349) Mar 01 20:06:01 ip-172-31-34-70 thingsboard.jar[1750750]: at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1080) Mar 01 20:06:01 ip-172-31-34-70 thingsboard.jar[1750750]: at java.base/java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1426) Mar 01 20:06:01 ip-172-31-34-70 thingsboard.jar[1750750]: at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290) Mar 01 20:06:01 ip-172-31-34-70 thingsboard.jar[1750750]: at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020) Mar 01 20:06:01 ip-172-31-34-70 thingsboard.jar[1750750]: at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656) Mar 01 20:06:01 ip-172-31-34-70 thingsboard.jar[1750750]: at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594) Mar 01 20:06:01 ip-172-31-34-70 thingsboard.jar[1750750]: at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:183)
In my opinion, the problem is the format of the message, because it doesn't add the
"telemetry":
needed for this kind of input value, but maybe it's another issue that I'm not seeing. Any help would be appreciatedThe text was updated successfully, but these errors were encountered: