-
-
Save domadev812/b8903ffdfcd31de650b916b9e1b7334d 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
| topic = "user/path/topic" |
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
| from pubnub.pnconfiguration import PNConfiguration | |
| from pubnub.pubnub import PubNub | |
| from pubnub.callbacks import SubscribeCallback | |
| pnconfig = PNConfiguration() | |
| pnconfig.subscribe_key = "my_subkey" | |
| pnconfig.publish_key = "my_pubkey" | |
| pnconfig.ssl = False | |
| pubnub = PubNub(pnconfig) | |
| class MySubscribeCallback(SubscribeCallback): | |
| def presence(self, pubnub, presence): | |
| pass # handle incoming presence data | |
| def status(self, pubnub, status): | |
| def message(self, pubnub, message): | |
| print(message) | |
| pubnub.add_listener(MySubscribeCallback()) | |
| pubnub.subscribe().channels('my_channel')async(callback).execute() |
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
| import paho.mqtt.client as mqtt | |
| def on_message(client, userdata, message): | |
| print(msg.topic, str(msg.payload)) | |
| def on_connect(client, userdata, flags, rc): | |
| client.subscribe('my_topic') | |
| client = mqtt.Client() | |
| client.on_message = on_message | |
| client.on_connect = on_connect | |
| client.connect('mqtt.pubnub.com', 1883) | |
| client.loop_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment