0
我有这个应用程序的一些麻烦。我需要的是,如果我检测到数据库(FIREBASE)的变化,特别是在'sala'和'ventilacion'节点中,该功能就会做它必须做的事情。如果数据库中没有任何变化,它不会无所事事。我正在使用python和pyrebase库。这是代码。非常感谢您的帮助。如何使用python检测firebase孩子的变化?
import pyrebase
import serial
import time
config = {
#firebase configurations
}
firebase = pyrebase.initialize_app(config)
db = firebase.database()
def ReconfiguracionFabrica():
ser.write('AT')
time.sleep(0.2)
ser.write('AT+RENEW')
time.sleep(0.3)
def ConfiguracionMaster():
time.sleep(0.5)
ser.write('AT+IMME1')
time.sleep(0.350)
ser.write('AT+ROLE1')
time.sleep(0.2)
ser=serial.Serial(port="/dev/ttyAMA0", baudrate=9600, timeout=1)
ReconfiguracionFabrica()
time.sleep(0.1)
ConfiguracionMaster()
time.sleep(0.1)
print "********** INICIO *************"
ser.flushInput()
contador=0
prender= ''
ventilacion1= ''
checkeo= ''
while True:
#if db.child("sala").: # It is the line where would be the conditional that allows me to detect any change only in the sala's node.
salidaLed1 = db.child("sala").get()
ser.write('AT')
time.sleep(0.1)
ser.write('AT+CON508CB16A7014')
time.sleep(0.1)
if salidaLed1.val()== True:
prender=";"
if salidaLed1.val()== False:
prender=","
ser.write('luz: %s \n' %(prender))
print ('luz: %s \n' %(prender))
time.sleep(1)
ser.read(checkeo)
if checkeo== 'j':
ReconfiguracionFabrica()
time.sleep(0.1)
ConfiguracionMaster()
嗨stofvl,感谢您的快速回答,我已经看到pyrebase库中的流方法,但不幸的是我不明白如何使用它。你能帮我用这个吗?我的firebase数据库没有任何路径。我有名叫'sala'和'ventilacion'的孩子。在这种情况下,我想检测孩子萨拉的变化。再次感谢您的帮助。 – JoaquinMiguens
@JoaquinMiguens:阅读[rest/database /#section-streaming](https://firebase.google.com/docs/reference/rest/database/#section-streaming)并相应地设置你的'sala'。 – stovfl
阅读文档后,我无法使其工作。我想如果有人能帮助我或指导我如何使其工作。谢谢。 – JoaquinMiguens