没有为记录器找到处理程序" pubnub"在询问消息

时间:2017-12-16 02:48:21

标签: python raspberry-pi pubnub

我现在正在使用pubnub。我正在向pubnub帐户发送一些消息(状态:on和status:off)但是当我想在我的覆盆子pi上运行我的python脚本时。我收到这个错误。

找不到记录器" pubnub"

的处理程序

我有最新的python版本 我有最新的pubnub版本

代码:

from pubnub.pnconfiguration import PNConfiguration
from pubnub.pubnub import PubNub
from pubnub.callbacks import SubscribeCallback
from pubnub.enums import PNOperationType, PNStatusCategory
from pubnub.pubnub import PubNub, SubscribeListener
import time
import RPi.GPIO as GPIO

pnconf = PNConfiguration()
pnconf.subscribe_key = "sub-c-e1af6266-e1d0-11e7-ad36-deb77ae39924"
pnconf.publish_key = "pub-c-6dbd1d39-2915-4df0-b99a-5b358cf69209"
pnconf.ssl = True
pubnub = PubNub(pnconf)

def my_publish_callback(envelope, status):
    # Check whether request successfully completed or not
    if not status.is_error():
        pass  # Message successfully published to specified channel.
    else:
        pass  # Handle message publish error. Check 'category' property to find out possible issue
        # because of which request did fail.
        # Request can be resent using: [status retry];

class MySubscribeCallback(SubscribeCallback):
    def presence(self, pubnub, presence):
        pass  # handle incoming presence data

    def status(self, pubnub, status):
        if status.category == PNStatusCategory.PNUnexpectedDisconnectCategory:
            pass  # This event happens when radio / connectivity is lost

        elif status.category == PNStatusCategory.PNConnectedCategory:
            # Connect event. You can do stuff like publish, and know you'll get it.
            # Or just use the connected event to confirm you are subscribed for
            # UI / internal notifications, etc
            pubnub.publish().channel("led").message("hello!!").async(my_publish_callback)
        elif status.category == PNStatusCategory.PNReconnectedCategory:
            pass
            # Happens as part of our regular operation. This event happens when
            # radio / connectivity is lost, then regained.
        elif status.category == PNStatusCategory.PNDecryptionErrorCategory:
            pass
            # Handle message decryption error. Probably client configured to
            # encrypt messages and on live data feed it received plain text.

    def message(self, pubnub, message):
        print(message.message)
        if 'status' in message.message:
            print(message.message['status'])
            whatToDo(message.message['status'])
        pass  # Handle new message stored in message.message

def whatToDo(status):
    if status == 'ON':
        print('Switch ON light')
        # switch on
        led.on()
    else:
        print('Swtich OFF light')
        # switch off
        led.off()

pubnub.add_listener(MySubscribeCallback())
pubnub.subscribe().channels('led').execute()

1 个答案:

答案 0 :(得分:0)

我必须为pubnub loggger初始化自己的处理程序

date_rank = 1
相关问题