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