Skip to content

Commit 29180cd

Browse files
committed
Get rid of usbrelay output
1 parent 9f14d59 commit 29180cd

3 files changed

Lines changed: 28 additions & 20 deletions

File tree

dyndb.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self,url="http://localhost:8000",region="eu-central-1"):
1212
self.table_log = self.dynamodb.Table('Temperature')
1313
self.table_cmd = self.dynamodb.Table('Commands')
1414

15-
def put_values(self,temperature1,temperature2,thermo_name="InsideHall",target_t=100,is_heating=0):
15+
def put_values(self,temperature1,temperature2,thermo_name="InsideHall",target_t=100,is_heating=0, boiler_state=-1):
1616
try:
1717
response=self.table_log.put_item(
1818
Item={
@@ -22,6 +22,7 @@ def put_values(self,temperature1,temperature2,thermo_name="InsideHall",target_t=
2222
'val2': get_val(temperature2),
2323
'target': get_val(target_t),
2424
'heating': get_val(is_heating),
25+
'boiler_state': get_val(boiler_state)
2526
}
2627
)
2728
except decimal.Inexact:
@@ -33,6 +34,7 @@ def put_values(self,temperature1,temperature2,thermo_name="InsideHall",target_t=
3334
'val2': float_to_decimal(temperature2),
3435
'target': float_to_decimal(target_t),
3536
'heating': get_val(int(is_heating)),
37+
'boiler_state': get_val(int(boiler_state)),
3638
}
3739
)
3840
return response

get_thermo.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def default(self, o):
3535

3636
for i in response['Items']:
3737
print(time.ctime(float(i['GetDate'])),'temp1',float(i.get('val1', -1)), 'temp2', float(i.get('val2', -1)),
38-
int(i.get('target',-1)),int(i.get('heating',-1)))
38+
'target temp',int(i.get('target',-1)),'heating cmd',int(i.get('heating',-1)),
39+
'boiler state', int(i.get('boiler_state',-1)))
3940

4041

thermd

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ import tconf
99
import bstate
1010
from w1thermsensor import W1ThermSensor
1111
import subprocess
12+
import os
13+
import sys
14+
15+
devnull = open(os.devnull, 'w')
16+
1217

1318

14-
sensor = W1ThermSensor()
1519

1620
def db2local(b, db):
1721
response=db.get_cmd(b.boiler_name,b.boiler_name)
@@ -25,27 +29,27 @@ def db2local(b, db):
2529

2630

2731
def boiler_state():
28-
out = subprocess.check_output([tconf.relay_cmd])
32+
out = subprocess.check_output([tconf.relay_cmd], stderr=devnull)
2933
if out:
3034
for l in out.splitlines():
3135
state = l.split('=')
32-
if len(state) == 1 and state[0] == tconf.relay:
36+
if len(state) == 2 and state[0] == tconf.relay:
3337
return state[1]
34-
return None
38+
return -1
3539

36-
def boiler_on():
37-
cur_s = boiler_state()
40+
def boiler_on(cur_s):
3841
if cur_s == tconf.relay_on:
3942
return
4043

41-
subprocess.check_output([tconf.relay_cmd, "{0}={1}".format(tconf.relay,tconf.relay_on)])
44+
subprocess.check_output([tconf.relay_cmd, "{0}={1}".format(tconf.relay,tconf.relay_on)],
45+
stderr=devnull)
4246

43-
def boiler_off():
44-
cur_s = boiler_state()
47+
def boiler_off(cur_s):
4548
if cur_s == tconf.relay_off:
4649
return
4750

48-
subprocess.check_output([tconf.relay_cmd, "{0}={1}".format(tconf.relay,tconf.relay_off)])
51+
subprocess.check_output([tconf.relay_cmd, "{0}={1}".format(tconf.relay,tconf.relay_off)],
52+
subprocess.devnull)
4953

5054
def now_day():
5155
now = datetime.datetime.now()
@@ -55,19 +59,19 @@ def now_day():
5559
return 1
5660

5761

58-
def run_cmd(cur_t, cmd):
62+
def run_cmd(cur_t, cmd, cur_s):
5963
target_t = cmd.get('target', tconf.def_temp)
6064
# command mode: 0 - always off; 1 - maintain target; 2 - target at night, 5 at day
6165
mode = cmd.get('heating', 1)
6266
if mode == 0:
63-
boiler_off();
67+
boiler_off(cur_s);
6468
else:
6569
if mode == 2 and now_day():
6670
target_t = tconf.def_temp
6771
if cur_t < target_t:
68-
boiler_on()
72+
boiler_on(cur_s)
6973
else:
70-
boiler_off()
74+
boiler_off(cur_s)
7175

7276

7377

@@ -84,21 +88,22 @@ boiler = bstate.Boiler(thermo_name)
8488
# Connect to Dynamodb
8589
db=dyndb.Tempdb(tconf.url,tconf.region)
8690

87-
91+
sensor = W1ThermSensor()
8892

8993
while True:
9094
boiler.read_state()
9195
temp_in_c1 = sensor.get_temperature()
9296
temp_in_c2 = sensor.get_temperature()
97+
cur_s = boiler_state()
9398
if temp_in_c1:
94-
print (time.time(),temp_in_c1, temp_in_c2, boiler.state['target'],boiler.state['heating'])
99+
print (time.time(),temp_in_c1, temp_in_c2, boiler.state['target'],boiler.state['heating'], cur_s)
95100
db.put_values(temp_in_c1, temp_in_c2, thermo_name,boiler.state['target'],
96-
boiler.state['heating'])
101+
boiler.state['heating'], cur_s)
97102
else:
98103
print ("ERR read invalid data from wired thermometr: '")
99104

100105
boiler_cmd = db2local(boiler, db)
101-
run_cmd(temp_in_c1, boiler_cmd)
106+
run_cmd(temp_in_c1, boiler_cmd, cur_s)
102107

103108
time.sleep(tconf.therm_rate)
104109

0 commit comments

Comments
 (0)