forked from ishanijanveja/HashHacks3_FutureGadgetsLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPython Code for connecting to Firebase.py
60 lines (56 loc) · 1.73 KB
/
Python Code for connecting to 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
59
60
import pyrebase
import platform
import os
import glob
import time
selfID="Car1" ##this is the dummy for the self's Number Plate unique ID
config={ #fill according to your firebase database
"apiKey": " AIzaSyAPumd637Cml2lncPQWARhnE0oei_AsyeU ",
"authDomain": "overtake-5888b.firebaseapp.com",
"databaseURL": "https://overtake-5888b.firebaseio.com/",
"storageBucket": "overtake-5888b.appspot.com"
}
firebase =pyrebase.initialize_app(config)
db=firebase.database()
#For turning LED Green/Red On or Off
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)
mypinG = 11
mypinR = 12
GPIO.setup(mypinG, GPIO.OUT, initial = 0)
GPIO.setup(mypinR, GPIO.OUT, initial = 0)
overtake=1
def uploadMess(tuSun,yeSun):
db.child("Groups").child(tuSun).update(yeSun)
def stream_handler(message):
print(message["data"])
overtake=int(message["data"])
if(overtake==0):
GPIO.output(mypinG, 1)
GPIO.output(mypinR, 0)
print("Overtake")
else:
GPIO.output(mypinG, 0)
GPIO.output(mypinR, 1)
print("Dont Overtake")
def getPlateID():
###Here goes the detction code for Number Plate
###Number Plate Detection Code Returns a number- Plate which is the unique id for the detected car
return 'Car2'
def PlatePresent():
if(getPlateID!=''):
return 1
else:
return 0
#print("Listening to stream")
#my_stream = db.child("Cars").child(Plate).stream(stream_handler)
PlateTemp='Temp'
while(True):
######
#checkForPlate
######
if(PlatePresent()!=0):
Plate=getPlateID();
if(Plate!=PlateTemp):
PlateTemp=Plate
my_stream = db.child("Cars").child(Plate).stream(stream_handler)