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

Can't publish data with timestamp (ts) through gw_send_telemetry #38

Open
zsamora opened this issue Mar 1, 2023 · 2 comments
Open

Can't publish data with timestamp (ts) through gw_send_telemetry #38

zsamora opened this issue Mar 1, 2023 · 2 comments

Comments

@zsamora
Copy link

zsamora commented Mar 1, 2023

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 appreciated

@zsamora
Copy link
Author

zsamora commented Mar 1, 2023

It worked while using: [{"ts": int(round(time()*1000)), "values": {"telemetryKey": "telemetryValue"}}]. So maybe you should correct the example in the link or removing the third condition in the function (telemetry.get("ts") is not None)

@Makodan
Copy link

Makodan commented May 5, 2024

Wow, I spent a lot of time resolving this. @zsamora Thank you, this is the solution. Array of dictionaries has to be used:
sensor_data = [{"ts": 1714591946064, "values":{"node_rx_RSSI": 1, "gw_powerlevel": 2, "node_tx_RSSI": 3, "powerlevel": 4, "voltage": 5}}]
Assignment:
sensor_data[0]['ts'] = int(time.time())*1000
Sending the telemetry:
gateway.gw_send_telemetry("some_device_name", sensor_data)

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

No branches or pull requests

2 participants