Pyrebase Raspberry Pi Python错误

时间:2018-02-10 22:04:40

标签: python python-3.x firebase raspberry-pi iot

我使用此代码进行开/关使用raspberry pi 3和firebase for raspberry pi 3但是出错了。我是python的新手。那么这个错误是什么意思以及如何解决这个错误?

#import Libraries
import RPi.GPIO as GPIO
import time
import pyrebase

#Firebase Configuration
config = {
  "apiKey": "xxxxx",
  "authDomain": "xxxxx",
  "databaseURL": "xxxxx",
  "storageBucket": "xxxxx"
}

firebase = pyrebase.initialize_app(config)

#GPIO Setup
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(18, GPIO.OUT)

#Firebase Database Intialization
db = firebase.database()

#While loop to run until user kills program
while(True):
    #Get value of LED 
    led = db.child("led").get()

    #Sort through children of LED(we only have one)
    for user in led.each():
        #Check value of child(which is 'state')
        if(user.val() == "OFF"):
            #If value is off, turn LED off
            GPIO.output(18, False)
        else:
            #If value is not off(implies it's on), turn LED on
            GPIO.output(18, True)

        #0.1 Second Delay
        time.sleep(0.1)   

错误是;

Traceback (most recent call last);
 File "/home/pi/Desktop/led.py", line 30, in <module>
  for user in led.each():
TypeError: 'NoneType' object is not iterable

0 个答案:

没有答案