SmartCradle v1
Baby smart cradle
database.py
Go to the documentation of this file.
1
9
10def send_temp_hum(a,b):
11 import pyrebase
12
13 config = {
14 "apiKey": "3bkkqHY9qniMHWG5w9Ck3yhrAJUh5Q4bUp3H9JA6",
15 "authDomain": "projeto-gamma.firebaseapp.com",
16 "databaseURL": "https://projeto-gamma.firebaseio.com",
17 "storageBucket": "projeto-gamma.appspot.com"
18 }
19
20 firebase = pyrebase.initialize_app(config)
21 db = firebase.database()
22
23
24 data = {
25 "humidity": float("{:.2f}".format(b)),
26 "temperature": float("{:.2f}".format(a))
27 }
28 db.child("users").child("1XdXWXC26aNQ5TrEIX1z2p5ipiH2").child("parameters").update(data)
29
30 return 1
31
32
33def get_swing_flag():
34 import pyrebase
35
36 config = {
37 "apiKey": "3bkkqHY9qniMHWG5w9Ck3yhrAJUh5Q4bUp3H9JA6",
38 "authDomain": "projeto-gamma.firebaseapp.com",
39 "databaseURL": "https://projeto-gamma.firebaseio.com",
40 "storageBucket": "projeto-gamma.appspot.com"
41 }
42
43 firebase = pyrebase.initialize_app(config)
44 db = firebase.database()
45 ret = db.child("users").child("1XdXWXC26aNQ5TrEIX1z2p5ipiH2").child("parameters").get()
46
47 x = int(ret.val()["swing_flag"])
48
49 if(x == None):
50 return -1
51
52 return x
53
54def get_live_flag():
55 import pyrebase
56
57 config = {
58 "apiKey": "3bkkqHY9qniMHWG5w9Ck3yhrAJUh5Q4bUp3H9JA6",
59 "authDomain": "projeto-gamma.firebaseapp.com",
60 "databaseURL": "https://projeto-gamma.firebaseio.com",
61 "storageBucket": "projeto-gamma.appspot.com"
62 }
63
64 firebase = pyrebase.initialize_app(config)
65 db = firebase.database()
66 ret = db.child("users").child("1XdXWXC26aNQ5TrEIX1z2p5ipiH2").child("parameters").get()
67
68 x = int(ret.val()["live_flag"])
69
70 if(x == None):
71 return -1
72
73 return x
74
75def send_notification_flag(b):
76 import pyrebase
77
78 config = {
79 "apiKey": "3bkkqHY9qniMHWG5w9Ck3yhrAJUh5Q4bUp3H9JA6",
80 "authDomain": "projeto-gamma.firebaseapp.com",
81 "databaseURL": "https://projeto-gamma.firebaseio.com",
82 "storageBucket": "projeto-gamma.appspot.com"
83 }
84
85 firebase = pyrebase.initialize_app(config)
86 db = firebase.database()
87
88
89 data = {
90 "notification_flag": int(b)
91 }
92 db.child("users").child("1XdXWXC26aNQ5TrEIX1z2p5ipiH2").child("parameters").update(data)
93
94 return 1
95
96def send_swing_flag(b):
97 import pyrebase
98
99 config = {
100 "apiKey": "3bkkqHY9qniMHWG5w9Ck3yhrAJUh5Q4bUp3H9JA6",
101 "authDomain": "projeto-gamma.firebaseapp.com",
102 "databaseURL": "https://projeto-gamma.firebaseio.com",
103 "storageBucket": "projeto-gamma.appspot.com"
104 }
105
106 firebase = pyrebase.initialize_app(config)
107 db = firebase.database()
108
109
110 data = {
111 "swing_flag": int(b)
112 }
113 db.child("users").child("1XdXWXC26aNQ5TrEIX1z2p5ipiH2").child("parameters").update(data)
114
115 return 1
116
117#def get_acc_id(b): probably will not be used
118 import pyrebase
119
120 config = {
121 "apiKey": "3bkkqHY9qniMHWG5w9Ck3yhrAJUh5Q4bUp3H9JA6",
122 "authDomain": "projeto-gamma.firebaseapp.com",
123 "databaseURL": "https://projeto-gamma.firebaseio.com",
124 "storageBucket": "projeto-gamma.appspot.com"
125 }
126
127 firebase = pyrebase.initialize_app(config)
128 db = firebase.database()
129
130 acc_ids = db.get()
131 x = 0
132 for child in acc_ids.each():
133 #print(int(acc_ids.val()["prod_id"]))
134 if (int(b) == int(child.val()["user_info"]["prod_id"])):
135 return x
136 x = x+1
137
138 return -1