Skip to content

Instantly share code, notes, and snippets.

@ralight
Created October 31, 2012 19:07
Show Gist options
  • Save ralight/3989161 to your computer and use it in GitHub Desktop.
Save ralight/3989161 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()
@ralight
Copy link
Author

ralight commented Oct 31, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment