-
-
Save nivertech/3993189 to your computer and use it in GitHub Desktop.
Print incoming MQTT messages with a maximum width of 32 characters.
This file contains hidden or 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 | |
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