Skip to content

Instantly share code, notes, and snippets.

@Veticus
Last active April 9, 2020 07:55
Show Gist options
  • Save Veticus/622d60698781645c0e820504d4bdadbf to your computer and use it in GitHub Desktop.
Save Veticus/622d60698781645c0e820504d4bdadbf to your computer and use it in GitHub Desktop.
A quick and dirty way to publish a string to a mqtt broker.
# Get the paho-mqtt library using pip: "pip3 install paho-mqtt"
import paho.mqtt.publish as publish
def mqttpublish(topic="paho/test/multiple", payload="multiple 2"):
msgs = [(topic, payload, 0, False)]
publish.multiple(msgs, hostname="broker.hivemq.com")
mqttpublish("paho/test/multiple", "TEST01")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment