Skip to content

Instantly share code, notes, and snippets.

@tofl
Created May 29, 2019 15:06
Show Gist options
  • Save tofl/71bddade0b8394e9c39edd0b2add0b66 to your computer and use it in GitHub Desktop.
Save tofl/71bddade0b8394e9c39edd0b2add0b66 to your computer and use it in GitHub Desktop.
import paho.mqtt.client as mqtt
import threading
import random
host = "192.168.99.100"
port = 1883
# Connexion
client = mqtt.Client("TomFlitterman")
client.connect(host, port)
# Publier des messages :
def setInterval(func,time):
e = threading.Event()
while not e.wait(time):
func()
def envoyerMessage():
randInt = random.randint(1, 50)
client.publish("test", randInt, 0, False)
setInterval(envoyerMessage, 2)
#client.publish(topic="test", payload="Hello world", qos=0, retain=False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment