Untitled

 avatar
unknown
plain_text
5 months ago
1.8 kB
2
Indexable
#importing pubnub libraries
from pubnub.pubnub import PubNub, SubscribeListener, SubscribeCallback, PNStatusCategory
from pubnub.pnconfiguration import PNConfiguration
from pubnub.exceptions import PubNubException
import pubnub
import RPi.GPIO as GPIO
from mfrc522 import SimpleMFRC522
pnconf = PNConfiguratry cleaning up at the end of your program instead!
ion()
# create pubnub_configuration_object
pnconf.publish_key = 'pub-c-457d49c1-ded9-40fb-9f36-400bafc3563b'# set pubnub publish_key
pnconf.subscribe_key = 'sub-c-abae8874-67d0-4eaf-9e80-65adbc98afba' # set pubnub subscibe_key
pnconf.uuid = '12345'
pubnub = PubNub(pnconf)
# create pubnub_object using pubnub_configuration_object
channel='lab-2'
# provide pubnub channel_name
data = {
'message': 'Test'
}
# data to be published
my_listener = SubscribeListener()
# create listner_object to read the msg from the Broker/Server
pubnub.add_listener(my_listener)
# add listner_object to pubnub_object to subscribe it
pubnub.subscribe().channels(channel).execute()
# subscribe the channel
my_listener.wait_for_connect()
# wait for the listener_obj to connect
print('connected')
# print confirmation msg
pubnub.publish().channel(channel).message(data).sync()
# publish the data to the mentioned channel
while True:
    result = my_listener.wait_for_message_on(channel)
    # Read the new msg on the channel
    print(result.message)
    print(result.message.keys())
    try:
        text = result.message
        print("Now place your tag to write")
        reader = SimpleMFRC522()
        reader.write(str(text))
        print("Written to the RFID")
    finally:
        GPIO.cleanup()
    try:
        id, text = reader.read()
        print(id)
        print(text)
    finally:
        GPIO.cleanup()
Editor is loading...
Leave a Comment