From 6d88a10acb75eeae9988afdbe048e885bc350128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=BCtke?= Date: Mon, 2 Jan 2023 13:13:11 -0400 Subject: [PATCH 1/2] updated to published api --- bin/user/windguru.py | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/bin/user/windguru.py b/bin/user/windguru.py index ec4369f..d327986 100644 --- a/bin/user/windguru.py +++ b/bin/user/windguru.py @@ -51,13 +51,13 @@ from urllib import urlencode import re import sys -import time +import hashlib import weewx import weewx.restx import weewx.units -VERSION = "0.2" +VERSION = "0.3" if weewx.__version__ < "3": raise weewx.UnsupportedFeature("weewx 3 is required, found %s" % @@ -129,17 +129,17 @@ def new_archive_record(self, event): self.archive_queue.put(event.record) + + class WindGuruThread(weewx.restx.RESTThread): _SERVER_URL = 'http://www.windguru.cz/upload/api.php' _DATA_MAP = {'temperature': ('outTemp', '%.1f'), # C 'wind_direction': ('windDir', '%.0f'), # degree 'wind_avg': ('windSpeed', '%.1f'), # knots 'wind_max': ('windGust', '%.1f'), # knots - 'mslp': ('barometer', '%.3f'), # hPa 'rh': ('outHumidity', '%.1f'), # % - 'rain': ('rain', '%.2f'), # mm - 'interval': ('interval', '%d'), # seconds - 'precip_interval': ('interval', '%d') # seconds + 'mslp': ('barometer', '%.3f'), # hPa + 'precip': ('hourRain', '%.2f'), # mm } def __init__(self, queue, station_id, password, manager_dict, @@ -174,26 +174,33 @@ def check_response(self, response): def format_url(self, in_record): # put everything into the right units and scaling record = weewx.units.to_METRICWX(in_record) + + # authentication + salt = "%d~salted" % record['dateTime'] + hash = hashlib.md5((salt + self.station_id + self.password).encode('utf-8')).hexdigest() + if 'windSpeed' in record and record['windSpeed'] is not None: record['windSpeed'] = _mps_to_knot(record['windSpeed']) if 'windGust' in record and record['windGust'] is not None: record['windGust'] = _mps_to_knot(record['windGust']) - # put data into expected structure and format - time_tt = time.localtime(record['dateTime']) values = { 'stationtype': 'weewx', 'uid': self.station_id, - 'date': time.strftime("%d.%m.%Y", time_tt), - 'time': time.strftime("%H:%M", time_tt) + 'salt': salt, + 'hash': hash, + 'interval': self.post_interval, + 'percip_interval': 3600 # hourly, because we pass hourRain as percipation value } - # TODO: Password md5, though WindGuru doesn't care at the moment - # values['password'] = self.password + for key in self._DATA_MAP: rkey = self._DATA_MAP[key][0] if rkey in record and record[rkey] is not None: values[key] = self._DATA_MAP[key][1] % record[rkey] + url = self.server_url + '?' + urlencode(values) + if weewx.debug >= 2: - logdbg('url: %s' % re.sub(r"password=[^\&]*", "password=XXX", url)) + logdbg('url: %s' % url) + return url From beef4cf2aa6caf0864f078b1b35313cfcc36f781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tobias=20L=C3=BCtke?= Date: Mon, 2 Jan 2023 13:19:54 -0400 Subject: [PATCH 2/2] slight improvements to the readme --- README.md | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 11cc8af..fbdaeb4 100644 --- a/README.md +++ b/README.md @@ -3,25 +3,34 @@ WeeWX WindGuru - WeeWX extension that publishes data to WindGuru Based in large part on the [WindFinder extension](https://github.com/weewx/weewx/wiki/windfinder) written by Matthew Wall. ## Installation -1. Register your WindGuru station - https://stations.windguru.cz/register.php +1. Register your [WindGuru station](https://stations.windguru.cz/register.php) 2. Download the extension - > wget wget -O weewx-windguru.zip https://github.com/claudobahn/weewx-windguru/archive/master.zip + + ```bash + wget -O weewx-windguru.zip https://github.com/claudobahn/weewx-windguru/archive/master.zip + ``` 3. Run the extension installer: - > wee_extension --install weewx-windguru.zip + ```bash + wee_extension --install weewx-windguru.zip + ``` 4. Update weewx.conf: + The station_id is also called UID and Weewx ID in windguru, it's a bit confusing. + ``` [StdRESTful] [[WindGuru]] - station_id = WindGuru_Station_id + station_id = WindGuru_Station_UID password = WindGuru_Password + post_interval = 60 ``` + + 5. Restart WeeWX > sudo /etc/init.d/weewx stop