-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathread_panel.py
executable file
·75 lines (62 loc) · 3.31 KB
/
read_panel.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
67
68
69
70
71
72
73
74
75
#! /usr/bin/env python3
###############################################################################
import atexit
import logging
import argparse
import serial
from lacrosse import WS3500
###############################################################################
def dump_all(ws):
"""
Dump All value to stdout
Take a ws3500 instance as unique argument
"""
print(f"Recording interval : {ws.recording_interval()} minute(s)")
print(f"Forecast is {ws.forecast()} with {ws.tendency()} trends")
print('')
print('Value | Current | Minumum | Maximum')
print('=====================X============X================================X===============================')
print(f"Internal Temperature | {ws.temp_int():+3.1f} | {ws.temp_int_min():+3.1f} on {ws.temp_int_min_time()} | {ws.temp_int_max():+3.1f} on {ws.temp_int_max_time()}")
print(f"Internal Humidity | {ws.humidity_int():3} % | {ws.humidity_int_min():3} % on {ws.humidity_int_min_time()} | {ws.humidity_int_max():3} % on {ws.humidity_int_max_time()}")
print(f"External Temperature | {ws.temp_ext():+3.1f} | {ws.temp_ext_min():+3.1f} on {ws.temp_ext_min_time()} | {ws.temp_ext_max():+3.1f} on {ws.temp_ext_max_time()}")
print(f"External Humidity | {ws.humidity_ext():3} % | {ws.humidity_ext_min():3} % on {ws.humidity_ext_min_time()} | {ws.humidity_ext_max():3} % on {ws.humidity_ext_max_time()}")
print(f"Dewpoint | {ws.dewpoint():+3.1f} | {ws.dewpoint_min():+3.1f} on {ws.dewpoint_min_time()} | {ws.dewpoint_max():+3.1f} on {ws.dewpoint_max_time()}")
print(f"Relative Pressure | {ws.rel_pressure():6} hPa | {ws.rel_pressure_min():6} hPa on {ws.rel_pressure_min_time()} | {ws.rel_pressure_max():6} hPa on {ws.rel_pressure_max_time()}")
###############################################################################
def close_serial(s):
"""
AtExit function that closes serial port
"""
s.close()
###############################################################################
###############################################################################
###############################################################################
if __name__ == '__main__':
parser = argparse.ArgumentParser(prog='read_pannel.py', description='WS3500 pannel reader')
parser.add_argument('-d', '--device', dest='DEVICE',
help='Device to access serial port',
default='/dev/ttyUSB0')
args = parser.parse_args()
logger = logging.getLogger('WS3500')
logger.setLevel(logging.ERROR) # DEBUG, INFO, WARNING, ERROR, CRITICAL
handler = logging.StreamHandler()
formatter = logging.Formatter(
'%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
ser = serial.Serial(
baudrate=300,
port=args.DEVICE,
bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE,
stopbits=serial.STOPBITS_ONE,
timeout=None,
writeTimeout=None,
interCharTimeout=None,
rtscts=0,
dsrdtr=None,
xonxoff=0
)
logger.info('serial port opened')
atexit.register(close_serial, ser)
dump_all(WS3500(ser, logger=logger))