首页 > 解决方案 > 当火焰传感器为真时,为什么我无法读取 firebase 上的“检测到火灾”?

问题描述

下面是我的火焰传感器代码,它通过 python 和树莓派在 firebase 上运行。我只需要阅读检测到的火灾它不起作用。

import RPi.GPIO as GPIO
import time

channel = 21

def callback(channel):
           print("Fire Detected")
x = GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime = 300)
y = GPIO.add_event_detect(channel, callback)

while True:
      if x is True:
       
db.child("account").child("email_password").child("p@gmail.com").child("write").child("flame").set("Fire Detected")
else: 
  
db.child("account").child("email_password").child("p@gmail.com").child("write").child("flame").set("Fire not Detected")

data = {
"flame": str(x)
}
db.child("account").child("email_password").child("p@gmail.com").child("write").set(data)
time.sleep(1)

GPIO.cleanup()

标签: pythonfirebaseraspberry-pisensors

解决方案


推荐阅读