24
PubNub IoT Platform Python By ANSHU PANDEY by ANSHU PANDEY | [email protected]

Python and pub nub iot cloud by anshu pandey

Embed Size (px)

Citation preview

Page 1: Python and pub nub iot cloud by anshu pandey

PubNub IoT PlatformPython

By ANSHU PANDEY

by ANSHU PANDEY | [email protected]

Page 2: Python and pub nub iot cloud by anshu pandey

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

Navigate to pubnub.com>> signup for an account or login with google

by ANSHU PANDEY | [email protected]

Page 4: Python and pub nub iot cloud by anshu pandey

Click on Create NEW APP+

by ANSHU PANDEY | [email protected]

Page 5: Python and pub nub iot cloud by anshu pandey

Create App

by ANSHU PANDEY | [email protected]

Page 6: Python and pub nub iot cloud by anshu pandey

After Creating app, scroll down to dashboard

by ANSHU PANDEY | [email protected]

Page 7: Python and pub nub iot cloud by anshu pandey

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 8: Python and pub nub iot cloud by anshu pandey

Click on New keyset to create a keyset

by ANSHU PANDEY | [email protected]

Page 9: Python and pub nub iot cloud by anshu pandey

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 10: Python and pub nub iot cloud by anshu pandey

Navigate to Blocks option from Left Menu & create a block

by ANSHU PANDEY | [email protected]

Page 11: Python and pub nub iot cloud by anshu pandey

Click on create to create event handlers

by ANSHU PANDEY | [email protected]

Page 12: Python and pub nub iot cloud by anshu pandey

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

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

Once the block is running, now you are all set to communicate via pubnub

by ANSHU PANDEY | [email protected]

Page 15: Python and pub nub iot cloud by anshu pandey

Navigate back to keyinfo to get keys

by ANSHU PANDEY | [email protected]

Page 16: Python and pub nub iot cloud by anshu pandey

Install python package for pubnub

pip install pubnub

by ANSHU PANDEY | [email protected]

Page 17: Python and pub nub iot cloud by anshu pandey

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

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

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 20: Python and pub nub iot cloud by anshu pandey

Navigate to debug console from left bottom option

by ANSHU PANDEY | [email protected]

Page 21: Python and pub nub iot cloud by anshu pandey

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

Now send data from pubnub, run your python code, analyse the messages

by ANSHU PANDEY | [email protected]

Page 23: Python and pub nub iot cloud by anshu pandey

Explore PubNub

by ANSHU PANDEY | [email protected]

Page 24: Python and pub nub iot cloud by anshu pandey

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]