Skip to content

Commit

Permalink
feat(WH57): Add support for parsing WH57 (lightning) data for the Eco…
Browse files Browse the repository at this point in the history
…wittClient. Note that the wview / wview_extended do not provide support for this and you'll have to supply your own schema extension.
  • Loading branch information
claudobahn committed Jul 8, 2020
1 parent 4c4a7fb commit 385c75a
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 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 @@ -694,6 +694,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 @@ -2361,9 +2374,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': 'daily_lightning_strikes',
'lightning_time': 'lightning_time',
'lightning': 'lightning_distance',
}

IGNORED_LABELS = [
Expand All @@ -2376,6 +2393,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 @@ -2419,6 +2437,11 @@ def parse(self, s):
pkt['rain'] = self._delta_rain(newtot, self._last_rain)
self._last_rain = newtot

if 'daily_lightning_strikes' in pkt:
new_strikes_total = pkt['daily_lightning_strikes']
pkt['lightning_strikes'] = 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

0 comments on commit 385c75a

Please sign in to comment.