python and pub nub iot cloud by anshu pandey
TRANSCRIPT
![Page 2: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/2.jpg)
Usecases for pubnub
• IoT Secure Messaging
• IoT Device Control
• Message Push Notification
• Home Automation Signalling
• Check this for more details https://stackoverflow.com/questions/20843632/what-is-advantage-and-disadvantage-of-using-pubnub-over-amazon-simple-notificati
by ANSHU PANDEY | [email protected]
![Page 3: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/3.jpg)
Navigate to pubnub.com>> signup for an account or login with google
by ANSHU PANDEY | [email protected]
![Page 7: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/7.jpg)
Click on your app, you just created, you might see a default keyset, which can be used to connect to PubNub and you can also create you own keyset.
by ANSHU PANDEY | [email protected]
![Page 9: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/9.jpg)
You should be able to get three keys which can be used to connect pubnubAllow pubnub Blocks as shown in below snapshot
by ANSHU PANDEY | [email protected]
![Page 12: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/12.jpg)
Name you handler, select after presence from second option, provide topic in third option and remember the topic
by ANSHU PANDEY | [email protected]
![Page 13: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/13.jpg)
The block is currently stopped, click on start block to start the block
by ANSHU PANDEY | [email protected]
![Page 14: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/14.jpg)
Once the block is running, now you are all set to communicate via pubnub
by ANSHU PANDEY | [email protected]
![Page 17: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/17.jpg)
Python code for Configuring PubNub
from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub, SubscribeListener
from pubnub.enums import PNStatusCategory
pnconfig = PNConfiguration()
pnconfig.publish_key = "pub-c-097ac4e7-23cf-45ee-980f-1775137fdf4e"
pnconfig.subscribe_key = "sub-c-a3cd0700-2bcd-11e7-97de-0619f8945a4f"
pnconfig.secret_key="sec-c-NzJhOGJlZmItNzQ2OC00MmM2LTg3ZjAtNWUxOWE2MjY4NTgx"
pnconfig.uuid="test"
pubnub = PubNub(pnconfig)
by ANSHU PANDEY | [email protected]
![Page 18: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/18.jpg)
Connecting to broker
my_listener = SubscribeListener()
pubnub.add_listener(my_listener)
pubnub.subscribe().channels('mytopic/new').execute()
my_listener.wait_for_connect()
print('connected')
by ANSHU PANDEY | [email protected]
![Page 19: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/19.jpg)
pubnub.publish().channel('mytopic/new').message({'fieldA': 'awesome', 'fieldB': 10}).sync()
result = my_listener.wait_for_message_on('mytopic/new')
print(result.message)
by ANSHU PANDEY | [email protected]
![Page 21: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/21.jpg)
Enter topic name, UUID as test because in program UUID taken is test, dnt put any authorization key
by ANSHU PANDEY | [email protected]
![Page 22: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/22.jpg)
Now send data from pubnub, run your python code, analyse the messages
by ANSHU PANDEY | [email protected]
![Page 24: Python and pub nub iot cloud by anshu pandey](https://reader031.vdocument.in/reader031/viewer/2022021815/5a64b8347f8b9abb6f8b46b9/html5/thumbnails/24.jpg)
I am Happy to see you on this slide,Now its your turn to do something exciting with this.
With more Expectation Anshu Pandeyhttps://www.linkedin.com/in/anshupandey/
by ANSHU PANDEY | [email protected]