Skip to content

Instantly share code, notes, and snippets.

@nivertech
Forked from ralight/printer.py
Created November 1, 2012 11:48
Show Gist options
  • Save nivertech/3993189 to your computer and use it in GitHub Desktop.
Save nivertech/3993189 to your computer and use it in GitHub Desktop.
Print incoming MQTT messages with a maximum width of 32 characters.
#!/usr/bin/python
import mosquitto
import textwrap
def on_message(mosq, obj, msg):
for s in textwrap.wrap(msg.payload, width=32):
print(s)
mqttc = mosquitto.Mosquitto()
mqttc.on_message = on_message
mqttc.connect("test.mosquitto.org", 1883, 60)
mqttc.subscribe("#", 0)
rc = 0
while rc == 0:
rc = mqttc.loop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment