I am trying to control an LED on my Raspberry Pi with the Pubnub platform.
However, when I want to execute a Python file that imports the Pubnub library with the following line:
from pubnub import Pubnub
I get this error message:
ImportError: cannot import name Pubnub
I did everything exactly as told in the tutorial. I even copied the .py classes from their Github repository.
This is my class:
import RPi.GPIO as GPIO
import time
import sys
from pubnub import Pubnub
GPIO.setmode (GPIO.BCM)
LED_PIN = 17
GPIO.setup(LED_PIN,GPIO.OUT)
pubnub = Pubnub(publish_key='xxxx', subscribe_key='xxxx')
channel = 'disco'
def _callback(m, channel):
print(m)
if m['led'] == 1:
for i in range(6):
GPIO.output(LED_PIN,True)
time.sleep(0.5)
GPIO.output(LED_PIN,False)
time.sleep(0.5)
print('blink')
def _error(m):
print(m)
pubnub.subscribe(channels=channel, callback=_callback, error=_error)