Permalink
Browse files

Merge pull request #150 from bitopen/bugfix

bugfixes: usb reconnect, round gust, wind direction calculation, rain/h, http header cookie
  • Loading branch information...
jpuigsegur committed Feb 25, 2018
2 parents 0177041 + 5c1071a commit 2d169e7613832afd37b2455baa0a00e15bdf8881
@@ -401,35 +401,19 @@ def WindSpeed(x,y):
"""
Obtains composite wind speed from x and y speeds
"""
return math.sqrt(x**2 + y**2)
return math.sqrt(x**2 + y**2)
def WindDir(x,y):
"""
Obtains composite wind direction from x and y speeds
"""
# Calculate polar coordinate angle
if x == 0:
if y > 0:
rAlpha = 90
elif y < 0:
rAlpha = -90
else:
rAlpha = 0
else:
if x > 0 and y > 0:
rAlpha = 180 / math.pi * math.atan(y/x)
elif x < 0 and y < 0:
rAlpha = 180 + 180 / math.pi * math.atan(y/x)
elif x > 0 and y < 0:
rAlpha = 180 / math.pi * math.atan(y/x)
else:
rAlpha = -180 + 180 / math.pi * math.atan(y/x)
degrees = math.degrees(math.atan2(x, y))
# Convert to compass bearing
if rAlpha < 90:
return 90 - rAlpha
else:
return 450 - rAlpha
if degrees < 0.0:
degrees += 360.0
return degrees
def WindDirTxt(d):
@@ -42,60 +42,70 @@ class WH1080Station(object):
name = 'Fine Offset WH1080 and compatibles'
def run(self, generate_event, send_event, context={}):
from pywws import WeatherStation
station = WeatherStation.weather_station()
for data, last_ptr, logged in station.live_data():
if not logged:
try:
if data['abs_pressure'] is not None:
e = generate_event('press')
e.value = data['abs_pressure']
send_event(e)
if data['temp_in'] is not None:
e = generate_event('temp')
e.sensor = 0
e.value = data['temp_in']
send_event(e)
if data['hum_in'] is not None:
e = generate_event('hum')
e.sensor = 0
e.value = data['hum_in']
send_event(e)
if data['temp_out'] is not None:
e = generate_event('temp')
e.sensor = 1
e.value = data['temp_out']
send_event(e)
if data['hum_out'] is not None:
e = generate_event('hum')
e.sensor = 1
e.value = data['hum_out']
send_event(e)
if data['rain'] is not None:
e = generate_event('rain')
e.total = data['rain']
e.rate = 0
send_event(e)
if data['wind_ave'] is not None and data['wind_dir'] < 16:
e = generate_event('wind')
e.create_child('mean')
e.mean.speed = data['wind_ave']
e.mean.dir = 22.5*(data['wind_dir'])
e.create_child('gust')
e.gust.speed = 0.0
e.gust.dir = 0.0
if data['wind_gust']:
e.gust.speed = data['wind_gust']
e.gust.dir = 22.5*(data['wind_dir'])
send_event(e)
except Exception, e:
self.logger.error(e)
# cyclic try connecting to weather station (when USB is disconnected)
while True:
try:
station = WeatherStation.weather_station()
for data, last_ptr, logged in station.live_data():
if not logged:
try:
if data['abs_pressure'] is not None:
e = generate_event('press')
e.value = data['abs_pressure']
send_event(e)
if data['temp_in'] is not None:
e = generate_event('temp')
e.sensor = 0
e.value = data['temp_in']
send_event(e)
if data['hum_in'] is not None:
e = generate_event('hum')
e.sensor = 0
e.value = data['hum_in']
send_event(e)
if data['temp_out'] is not None:
e = generate_event('temp')
e.sensor = 1
e.value = data['temp_out']
send_event(e)
if data['hum_out'] is not None:
e = generate_event('hum')
e.sensor = 1
e.value = data['hum_out']
send_event(e)
if data['rain'] is not None:
e = generate_event('rain')
e.total = data['rain']
e.rate = 0
send_event(e)
if data['wind_ave'] is not None and 0 <= data['wind_dir'] < 16:
dir_degrees = data['wind_dir'] * 22.5 # 360 / 16 = 22.5
e = generate_event('wind')
e.create_child('mean')
e.mean.speed = data['wind_ave']
e.mean.dir = dir_degrees
e.create_child('gust')
if data['wind_gust'] is not None:
e.gust.speed = data['wind_gust']
e.gust.dir = dir_degrees
else:
e.gust.speed = None
e.gust.dir = None
send_event(e)
except Exception, e:
self.logger.error(e)
except IOError, e:
self.logger.error('Exception IOError: ' + str(e))
finally:
time.sleep(30)
@@ -161,7 +161,7 @@ def get_data(self):
# Wind gust cannot be smaller than wind average
# (might happen due to different sampling periods)
if data['wind'] <= self._wind_gust:
data['wind_gust'] = self._wind_gust
data['wind_gust'] = round(self._wind_gust, 1)
else:
data['wind_gust'] = round(data['wind'], 1)
else:
@@ -136,7 +136,7 @@ def do_GET(self):
self.send_response(302)
self.send_header('Location', self.headers["Referer"] if self.headers.has_key("Referer") else "/")
self.wfile.write(cookie)
self.wfile.write(cookie.output()+'\r\n')
self.end_headers()
return
@@ -1,9 +1,9 @@
#from wfcommon.units import unit_roll
#def unitstr(m,u)
#if $getVar('http', False)
<a href="-set-?s=units&k=$m&v=$unit_roll($m,$u)">$u</a>
<a href="-set-?s=units&k=$m&v=$unit_roll($m,$u)">$u</a>#slurp
#else
$u
$u#slurp
#end if
#end def
<!DOCTYPE html>

0 comments on commit 2d169e7

Please sign in to comment.