Skip to content

Instantly share code, notes, and snippets.

@andypiper
Last active May 16, 2023 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save andypiper/1219095 to your computer and use it in GitHub Desktop.
Save andypiper/1219095 to your computer and use it in GitHub Desktop.
MQTT blaster - repeated publish on a topic
#!/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