-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththermo_data.py
51 lines (42 loc) · 1.29 KB
/
thermo_data.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
#!/usr/bin/python
import sys
import time
import dyndb
import serio
import tconf
import bstate
import json
import zmq
if len(sys.argv)==3:
tty_name=sys.argv[1]
thermo_name=sys.argv[2]
else:
tty_name=tconf.tty
thermo_name=tconf.thermo_name
#read boiler state file
boiler = bstate.Boiler(thermo_name)
# Init serial
tty=serio.Serial(tty_name)
time.sleep(3)
# Connect to Dynamodb
db=dyndb.Tempdb(tconf.url,tconf.region)
#init zmq pub channel
context = zmq.Context()
pub_channel = context.socket(zmq.PUB)
pub_channel.bind("tcp://*:5555")
while True:
tty.swrite("\n")
time.sleep(0.5)
boiler.read_state()
values=tty.sread().split()
if len(values) == 3:
print time.time(),values[0],values[1],boiler.state['target'],boiler.state['heating']
db.put_values(values[0],values[1],thermo_name,boiler.state['target'],
boiler.state['heating'])
pub_channel.send_string(json.dump({'thermometer':thermo_name, 'temeprature':values[0],
'humidity':values[1]} ))
else:
print ("ERR read invalid data from serial: '")
print values
time.sleep(tconf.therm_rate)
tty.sclose()