· 7 years ago · May 12, 2018, 11:44 AM
1import pyrebase
2
3from pusher_push_notifications import PushNotifications
4config = {
5 'apiKey': "***********************************",
6 'authDomain': "arfduinopushnotification.firebaseapp.com",
7 'databaseURL': "https://arduinopushnotification.firebaseio.com",
8 'projectId': "arduinopushnotification",
9 'storageBucket': "arduinopushnotification.appspot.com",
10 'messagingSenderId': "************"
11 }
12
13firebase = pyrebase.initialize_app(config)
14db = firebase.database()
15pn_client = PushNotifications(
16 instance_id='*****************************',
17 secret_key='**************************',
18)
19
20value = 0
21value1 = 0
22
23
24def stream_handler(message):
25 global value
26 print(message)
27 if message['data'] is 1:
28 value = message['data']
29 return value
30
31
32def stream_handler1(message):
33 global value1
34 print(message)
35 if message['data'] is 1:
36 value1 = message['data']
37 return value1
38
39
40if value == 1 & value1 == 1:
41 response = pn_client.publish(
42 interests=['hello'],
43 publish_body={
44 'apns': {
45 'aps': {
46 'alert': 'Hello!',
47 },
48 },
49 'fcm': {
50 'notification': {
51 'title': 'Notification',
52 'body': 'Fall Detected !!',
53 },
54 },
55 },
56 )
57 print(response['publishId'])
58
59
60my_stream = db.child("Fall_Detection_Status").stream(stream_handler)
61my_stream1 = db.child("Fall_Detection_Status1").stream(stream_handler1)