Skip to content

Instantly share code, notes, and snippets.

@prohazko2
Created February 10, 2022 14:51
Show Gist options
  • Save prohazko2/834d74ae5c2ac1fd0e4efcc6005758f1 to your computer and use it in GitHub Desktop.
Save prohazko2/834d74ae5c2ac1fd0e4efcc6005758f1 to your computer and use it in GitHub Desktop.
from random import uniform
from threading import Timer
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("on_connect rc: [%d]" % (rc))
def on_disconnect(client, userdata, rc):
print("disconnected with rtn code [%d]" % (rc))
client = mqtt.Client(client_id="mqtt-olegprohazko-jboetm")
client.tls_set("isrgrootx1.pem",
# certfile="cert.pem",
# keyfile="key.pem"
)
client.on_connect = on_connect
client.on_disconnect = on_disconnect
#client.on_log = on_log
client.connect("dev.rightech.io", 8883, 60)
def publish():
temp = round(uniform(20, 30), 2)
client.publish("state/temp", temp, qos=0)
Timer(10, publish).start()
Timer(1, publish).start()
client.loop_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment