-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase_reciever.py
executable file
·66 lines (45 loc) · 1.51 KB
/
firebase_reciever.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
61
62
63
64
65
66
#!/usr/bin/python3
path = '/home/pi/IR-Remote-hacking/'
import time
from firebase import firebase
import json
import os
#import IR messages
from IR_messages import messages
myDataBase = 'https://mydatabase-f7de1.firebaseio.com/'
#start fire base
firebase = firebase.FirebaseApplication(myDataBase,None)
try:
#get specific snapshot: IR
result = firebase.get('IR','IR_ctr')
except:
print('Firebase error')
#check if data was retrieved
if result:
data = json.loads(result)
print(data)
#check if there is a command in the data
if 'COMMAND' in data:
#check if it's a valid command
if isinstance(data['COMMAND'], str): #check if its a string
print('Command found: ' + data['COMMAND'])
if data['COMMAND'] in messages:
print('Translates to IR message:')
print(messages[data['COMMAND']])
#send command to transmitter
os.system(path + 'AC_control.py ' + data['COMMAND'])
#update most recent command sent
#this gives feedback that message was recieved
firebase.put('IR','past_IR_ctr',result)
else:
print('Not a valid command')
else:
print('Error: non string input')
#delete command
firebase.delete('IR','IR_ctr')
else:
print('No command found')
else:
print('No data found')
#log temperature
os.system(path + 'LogTemp.py ')