I got a python program on Raspberry Pi 3B sending data on Thingsboard. The device in Thingsboard is connected as a single entity to the dashboard. When running the program, showing the data on dashboard's charts and cards works, and server-side RPC commands can be sent trough the rule chain. But the control widgets claim that "Device is offline."
Here's the Raspberry's code:
import paho.mqtt.client as mqtt
import time
import json
import random
def on_message(client, data, message):
print json.loads(message.payload)
def main():
client = mqtt.Client("python1")
client.connected_flag=False
client.suppress_puback_flag=False
client.on_message = on_message
token=[DEVICE ID]
if token !="":
pass
client.username_pw_set(token, "")
client.connect([MY THINGSBOARD HOST'S IP], 1883)
client.subscribe("v1/devices/me/attributes", 1)
client.subscribe("v1/devices/me/rpc/request/+", 1)
time.sleep(2)
while not client.connected_flag:
client.loop()
while True:
message = {"number": random.randint(0, 100)};
message_json = json.parse(message)
client.publish("v1/devices/me/telemetry", message_json, 1)
client.loop_start()
time.sleep(3)
client.loop_stop()
if __name__== '__main__':
main()
How can I get the control widgets to realize that device is online?