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

Add support for parsing WH57 (lightning) data for the EcowittClient #72

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
27 changes: 26 additions & 1 deletion bin/user/interceptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@
GW1000 - 433MHz
GW1000A - 868MHz
GW1000B - 915MHz
GW1000BU - 915MHz with better rang
GW1000BU - 915MHz with better range

The transmission to wunderground can be captured using the 'wu-client' mode.
The transmission using ecowitt protocol (see the 'customize' page in the WSView
Expand Down Expand Up @@ -397,6 +397,8 @@ class Consumer(object):
'soilMoist4': 'soil_moisture_4',
'leafWet1': 'leafwetness_1',
'leafWet2': 'leafwetness_2',
'lightning_strike_count': 'lightning_strike_count',
'lightning_distance': 'lightning_distance',
# these are not in the wview schema
'pm2_5': 'pm2_5',
'extraTemp4': 'temperature_4',
Expand Down Expand Up @@ -695,6 +697,19 @@ def _delta_rain(rain, last_rain):
return rain
return rain - last_rain

@staticmethod
def _delta_strikes(strikes, last_strikes):
if strikes is None:
return None
if last_strikes is None:
loginf("skipping lightning strikes measurement of %s: no last strikes" % strikes)
return None
if strikes < last_strikes:
loginf("lightning strikes wraparound detected: new=%s last=%s" %
(strikes, last_strikes))
return strikes
return strikes - last_strikes

@staticmethod
def decode_float(x):
return None if x is None else float(x)
Expand Down Expand Up @@ -2362,9 +2377,13 @@ class Parser(Consumer.Parser):
'wh25batt': 'wh25_battery',
'wh26batt': 'wh26_battery',
'wh40batt': 'wh40_battery',
'wh57batt': 'wh57_battery',
'wh65batt': 'wh65_battery',
'pm25_ch1': 'pm2_5',
'pm25batt1': 'pm25_battery',
'lightning_num': 'lightning_strike_count',
'lightning_time': 'lightning_time',
'lightning': 'lightning_distance',
}

IGNORED_LABELS = [
Expand All @@ -2377,6 +2396,7 @@ class Parser(Consumer.Parser):
def __init__(self):
self._last_rain = None
self._rain_mapping_confirmed = False
self._last_strikes_total = None

def parse(self, s):
pkt = dict()
Expand Down Expand Up @@ -2420,6 +2440,11 @@ def parse(self, s):
pkt['rain'] = self._delta_rain(newtot, self._last_rain)
self._last_rain = newtot

if 'lightning_strike_count' in pkt:
new_strikes_total = pkt['lightning_strike_count']
pkt['lightning_strike_count'] = self._delta_strikes(new_strikes_total, self._last_strikes_total)
self._last_strikes_total = new_strikes_total

except ValueError as e:
logerr("parse failed for %s: %s" % (s, e))
return pkt
Expand Down