Last active
August 27, 2022 14:20
-
-
Save hakxcore/98e30b0e8802b2a1977a4025905eec3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## Go login on https://demo.thingsboard.io | |
## replace my access token with yours | |
## and see the magic rest of the instructions from your teacher i'm not your teacher. | |
import paho.mqtt.client as mqtt | |
from time import sleep | |
import random | |
def on_connect(client, userdata, flags, rc): | |
if rc==0: | |
print("connected ok") | |
client=mqtt.Client() | |
topic='v1/devices/me/telemetry' | |
access_token="KXtkbg9FEWMNLp5or85z" #use yours access-token (and its not sensitive :) | |
port=1883 | |
broker_name='demo.thingsboard.io' | |
client.username_pw_set(access_token) | |
client.connect(broker_name, port, 1) | |
client.on_connect=on_connect | |
while(True): | |
x=random.randint(0,200) | |
print("Random value=",x) | |
msg='{"Random Value":" '+ str(x) + ' "}' | |
client.publish(topic,msg) | |
sleep(1.5) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment