Skip to content

Instantly share code, notes, and snippets.

@ralight
ralight / utf8.py
Created March 17, 2013 16:56
Testing Python and mosquitto.py utf8 encoding.
#!/usr/bin/python
# vim: set fileencoding=utf8 :
import mosquitto
import sys
reload(sys)
sys.setdefaultencoding('utf8')
def on_message(mosq, obj, msg):
print(msg.topic + " : " + msg.payload)
@ralight
ralight / retained.py
Last active December 14, 2015 07:08
Retained message test, with QoS=2.
#!/usr/bin/python
import mosquitto
import time
pub_sent = False
def pub_on_connect(mosq, obj, rc):
mosq.publish("/A/B", "message one", 2, True)
mosq.publish("/A/B", "message two", 2, True)
@ralight
ralight / printer.py
Created October 31, 2012 19:07
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()