Last active
May 16, 2023 12:08
-
-
Save andypiper/1219095 to your computer and use it in GitHub Desktop.
MQTT blaster - repeated publish on a topic
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
#!/usr/bin/python | |
# | |
# simple script to repeatedly publish an MQTT message | |
# | |
# uses the Python MQTT client from the Paho project | |
# http://eclipse.org/paho | |
# | |
# Andy Piper @andypiper http://andypiper.co.uk | |
# | |
# 2011/09/15 first version | |
# 2012/05/28 updated to use new pure python client from mosquitto | |
# 2014/02/03 updated to use the Paho client | |
# | |
# pip install paho-mqtt | |
# python blast.py | |
import paho.mqtt.client as paho | |
import os | |
import time | |
broker = "m2m.eclipse.org" | |
port = 1883 | |
mypid = os.getpid() | |
client_uniq = "pubclient_"+str(mypid) | |
mqttc = paho.Client(client_uniq, False) #nocleanstart | |
#connect to broker | |
mqttc.connect(broker, port, 60) | |
#remain connected and publish | |
while mqttc.loop() == 0: | |
msg = "test message "+time.ctime() | |
mqttc.publish("timesample", msg, 0, True) #qos=0, retain=y | |
print "message published" | |
time.sleep(1.5) | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment