Created
February 10, 2022 14:51
-
-
Save prohazko2/834d74ae5c2ac1fd0e4efcc6005758f1 to your computer and use it in GitHub Desktop.
This file contains 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
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