18 lines
516 B
Python
Raw Normal View History

2023-04-03 10:09:53 +02:00
import paho.mqtt.client as mqtt
import random
import time
mqttBroker = "mqtt.eclipseprojects.io"
2023-04-03 10:25:46 +02:00
client1 = mqtt.Client("Temperature")
client1.connect(mqttBroker)
2023-04-03 10:09:53 +02:00
while True:
randNumber = random.randint(0, 20)
2023-04-03 10:25:46 +02:00
client1.publish("TEMPERATURE", randNumber)
2023-04-03 10:09:53 +02:00
print("Published " + str(randNumber) + " to topic TEMPERATURE")
2023-04-03 10:25:46 +02:00
time.sleep(2)
randNumber = random.randint(0, 100)
client1.publish("HUMIDITY", randNumber)
print("Published " + str(randNumber) + " to topic HUMIDITY")
2023-04-03 10:09:53 +02:00
time.sleep(2)