Created
September 16, 2013 07:27
-
-
Save jpmens/6577606 to your computer and use it in GitHub Desktop.
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/env python | |
| import mosquitto | |
| import ssl | |
| def on_connect(mosq, userdata, rc): | |
| print("Connect: rc: "+str(rc)) | |
| def on_message(mosq, userdata, msg): | |
| print "%s (qos=%s, r=%s) %s" % (msg.topic, str(msg.qos), msg.retain, str(msg.payload)) | |
| def on_publish(mosq, userdata, mid): | |
| print("mid: "+str(mid)) | |
| def on_subscribe(mosq, userdata, mid, granted_qos): | |
| print("Subscribed: "+str(mid)+" "+str(granted_qos)) | |
| def on_disconnect(mosq, userdata, rc): | |
| print "OOOOPS! disconnect" | |
| mqttc = mosquitto.Mosquitto('py-jp1', clean_session=True) | |
| mqttc.on_message = on_message | |
| mqttc.on_connect = on_connect | |
| mqttc.on_disconnect = on_disconnect | |
| mqttc.on_publish = on_publish | |
| mqttc.on_subscribe = on_subscribe | |
| mqttc.tls_insecure_set(True) # optional: avoid check certificate name if true | |
| mqttc.tls_set('root.ca', | |
| cert_reqs=ssl.CERT_REQUIRED, | |
| tls_version=1 | |
| ) | |
| mqttc.connect("localhost", 8883, 60) | |
| mqttc.publish("p1", "Hi", 0) | |
| mqttc.loop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@matbor What version of Python are you running, on which platform? (
python -V)