2017-10-20 77 views

回答

0

多次嘗試後收到此導入錯誤我剛好重新啓動我的系統解決了這個錯誤。

這裏是我的工作代碼,當火災數據庫中的值發生變化時觸發通知。

from pyfcm import FCMNotification 
import pyrebase 

push_service = FCMNotification(api_key="type server key here") 
registration_id = "get this token from your app" 
message_title = "Fire Alert" 
message_body = "Fire Breakage dehradun" 

config = { 
"apiKey": "", 
"authDomain": "", 
"databaseURL": "", 
"projectId": "", 
"storageBucket": "", 
"messagingSenderId": "" 
}; 

firebase = pyrebase.initialize_app(config) 
db = firebase.database() 
def stream_handler(post): 
    print(post) 
    if (post['data'] is 1): 
     result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title, message_body=message_body) 
     print (result) 
my_stream = db.child("fire_sensor_status").stream(stream_handler, None) 

希望這將幫助你:)