Last active
August 29, 2015 14:23
-
-
Save stephenlb/b4ea0034839ccbc2aa03 to your computer and use it in GitHub Desktop.
MQTT PubNub Demo
This file contains 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 | |
from mosquitto import Mosquitto | |
publish_key = "demo" | |
subscribe_key = "demo" | |
channel_name = "F" | |
client_uuid = "2fb96def5" | |
mqtt_hostname = "mqtt.pubnub.com" | |
mqtt_connect = publish_key + "/" + subscribe_key + "/" + client_uuid | |
mqtt_topic = publish_key + "/" + subscribe_key + "/" + channel_name | |
mosq_object = Mosquitto(mqtt_connect) | |
def on_message( mosq, obj, msg ): | |
print( msg.payload, msg.topic ) | |
mosq_object.on_message = on_message | |
mosq_object.connect(mqtt_hostname) | |
mosq_object.publish( mqtt_topic, "Hello World!" ) | |
mosq_object.subscribe(mqtt_topic) | |
mosq_object.loop_forever() |
Kindly where the documentation for the constructer Mosquitto("some string here")
what does the parameter for that constructor mean? because in the mqtt for paho project, the constructor takes 4 parameters, and the one that is close to your case is the client id. Thus, do you represent your client s using that kind of contacination ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Execution Example:
Install Dependencies
curl -Ls https://gist.githubusercontent.com/stephenlb/b4ea0034839ccbc2aa03/raw/df081c8a501284aada19730e910dc1c6da61a780/mqtt.py | python