-
Notifications
You must be signed in to change notification settings - Fork 17
/
sensor_W831.py
130 lines (87 loc) · 3.69 KB
/
sensor_W831.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
###########################################################################
# Sint Wind PI
# Copyright 2012 by Tonino Tarsi <tony.tarsi@gmail.com>
#
# Please refer to the LICENSE file for conditions
# Visit http://www.vololiberomontecucco.it
#
##########################################################################
"""This module defines the base sensor Ventus W831 """
import threading
import time
import config
import random
import datetime
import sqlite3
from TTLib import *
import sys
import subprocess
import globalvars
import meteodata
import sensor_thread
import sensor
import TTLib
import thread
from ctypes import *
def get_wind_dir_text():
"""Return an array to convert wind direction integer to a string."""
return ['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW']
forecastMap = { 0:'Grande Nevicata', 1:'Neve Leggera ', 2:'Temporale', 3:'Pioggia Leggera', 4:'Nuvoloso', 5:'Qualche Nuvola', 6:'Soleggiato' }
class Sensor_W831(sensor.Sensor):
def __init__(self,cfg ):
threading.Thread.__init__(self)
sensor.Sensor.__init__(self,cfg )
def run(self):
pass
def Detect(self):
return True
def GetData(self):
seconds = datetime.datetime.now().second
if ( seconds < 30 ):
time.sleep(30-seconds)
else:
time.sleep(90-seconds)
try:
output = subprocess.check_output(["./te923tool-0.6.1/te923con"]);
data = output.split(":")
#print data
globalvars.meteo_data.status = 0
globalvars.meteo_data.last_measure_time = datetime.datetime.now()
globalvars.meteo_data.idx = globalvars.meteo_data.last_measure_time
globalvars.meteo_data.temp_in = float(data[1])
globalvars.meteo_data.hum_in = int(data[2])
globalvars.meteo_data.temp_out = float(data[3])
globalvars.meteo_data.hum_out = int(data[4])
globalvars.meteo_data.abs_pressure = float(data[13])
globalvars.meteo_data.wind_ave = (float(data[18])*3.6)*self.cfg.windspeed_gain + self.cfg.windspeed_offset
globalvars.meteo_data.wind_gust = (float(data[19])*3.6)*self.cfg.windspeed_gain + self.cfg.windspeed_offset
globalvars.meteo_data.rain = int(data[21])
globalvars.meteo_data.delay = 0
wind_dir = int(data[17])
if ( wind_dir < 16 ):
globalvars.meteo_data.wind_dir = wind_dir * 22.5
globalvars.meteo_data.wind_dir_code = get_wind_dir_text()[wind_dir]
else:
globalvars.meteo_data.wind_dir_code = None
globalvars.meteo_data.wind_dir_code = None
globalvars.meteo_data.illuminance = None
globalvars.meteo_data.uv = None
except:
log("Error reading station data")
# unused variables
#uv = int(data[14])
#forecast = int(data[15])
#stormwarning = int(data[16])
#forecastTxt = forecastMap.get(forecast, str(forecast))
#print "VENTUS-W831 Barometer Forecast: " , forecastTxt
# TO REMOVE
if ( globalvars.meteo_data.abs_pressure == 0 ) :
globalvars.meteo_data.abs_pressure = None
sensor.Sensor.GetData(self)
if __name__ == '__main__':
configfile = 'swpi.cfg'
cfg = config.config(configfile)
ss = Sensor_W831(cfg)
ss.active = False
while ( 1 ) :
pass