Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to published API and some fixes #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 20 additions & 13 deletions bin/user/windguru.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" %
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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