-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoor_control_by_firebase.py
58 lines (46 loc) · 1.63 KB
/
door_control_by_firebase.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# This code achieving changing door states (lock || unlock) via Firebase (backend)
import RPi.GPIO as GPIO
import time
import doorControl
import pyrebase
# Firebase configuration
# serviceAccount: path of the json file might need to be fixed
config = {
"apiKey": "AIzaSyDH_J9AF-YES_nlB8NQxCs78fkz-GqSzQk",
"authDomain": "smartdoor-f5862.firebaseapp.com",
"databaseURL": "https://smartdoor-f5862.firebaseio.com",
"storageBucket": "smartdoor-f5862.appspot.com",
"serviceAccount": "/home/pi/Documents/smartdoor-f5862-firebase-adminsdk-fg4g8-71b2f73eb4.json"
}
firebase = pyrebase.initialize_app(config)
# Firebase Database Intialization
db = firebase.database()
# GPIO settings
GPIO.setwarnings(False)
def checkFBstatus():
doorControl.door().lock()
config = {
"apiKey": "AIzaSyDH_J9AF-YES_nlB8NQxCs78fkz-GqSzQk",
"authDomain": "smartdoor-f5862.firebaseapp.com",
"databaseURL": "https://smartdoor-f5862.firebaseio.com",
"storageBucket": "smartdoor-f5862.appspot.com",
"serviceAccount": "/home/pi/Documents/smartdoor-f5862-firebase-adminsdk-fg4g8-71b2f73eb4.json"
}
firebase = pyrebase.initialize_app(config)
# Firebase Database Intialization
db = firebase.database()
status = db.child("FrontDoor").get()
for user in status.each():
if(user.val() == "unlocked"):
doorControl.door().unlock()
time.sleep(10)
doorControl.door().lock()
else:
doorControl.door().lock()
try:
while(True):
checkFBstatus()
continue
except KeyboardInterrupt:
doorControl.door().unlock()
doorControl.door().shutdown()