From 77481e055490ca0101f6331e08f6f6bfb8f09d66 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Fri, 17 Apr 2015 16:58:45 -0400 Subject: [PATCH] log dodgey rainfall reports --- bin/weewx/drivers/acurite.py | 19 ++++++++++++------- docs/changes.txt | 19 ++++++++++--------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/bin/weewx/drivers/acurite.py b/bin/weewx/drivers/acurite.py index 0a41d5bf..5e5cc8b3 100644 --- a/bin/weewx/drivers/acurite.py +++ b/bin/weewx/drivers/acurite.py @@ -18,7 +18,7 @@ # Thanks to Weather Guy and Andrew Daviel (2015) # decoding of the R3 messages # -# Slow-clap thanks to Michael Walsh +# golf clap to Michael Walsh # http://forum1.valleyinfosys.com/index.php # # No thanks to AcuRite or Chaney instruments. They refused to provide any @@ -288,6 +288,7 @@ X1 - 2 bytes # FIXME: decode inside humidity # FIXME: decode historical records +# FIXME: perhaps retry read when dodgey data or short read? from __future__ import with_statement import syslog @@ -295,6 +296,7 @@ import time import usb import weewx.drivers +import weewx.wxformulas DRIVER_NAME = 'AcuRite' DRIVER_VERSION = '0.15' @@ -402,7 +404,8 @@ class AcuRiteDriver(weewx.drivers.AbstractDevice): ntries = 0 yield packet next_read = min(self.r1_next_read, self.r2_next_read) - delay = max(next_read - time.time(), self.polling_interval) + delay = max(int(next_read - time.time() + 1), + self.polling_interval) logdbg("next read in %s seconds" % delay) time.sleep(delay) except (usb.USBError, weewx.WeeWxIOError), e: @@ -417,11 +420,13 @@ class AcuRiteDriver(weewx.drivers.AbstractDevice): def _augment_packet(self, packet): # calculate the rain delta from the total if 'rain_total' in packet: - if self.last_rain is not None: - packet['rain'] = packet['rain_total'] - self.last_rain - else: - packet['rain'] = None - self.last_rain = packet['rain_total'] + total = packet['rain_total'] + if (total is not None and self.last_rain is not None and + total < self.last_rain): + loginf("rain counter decrement ignored:" + " new: %s old: %s" % (total, self.last_rain)) + packet['rain'] = wxformulas.calculate_rain(total, self.last_rain) + self.last_rain = total # no wind direction when wind speed is zero if 'windSpeed' in packet and not packet['windSpeed']: diff --git a/docs/changes.txt b/docs/changes.txt index 41bc74e0..13932094 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -38,17 +38,18 @@ should the alarm expression include a variable not in the archive record. Added better recovery from USB failures in the ws28xx driver. -Improved timing algorithm for AcuRite data. Thanks to Brett Warden. - Fixed bug that shows itself if marker_size is not specified in skin.conf -Added acurite log entries to logwatch script. Thanks to Andy. - -Prevent negative rainfall amounts in acurite driver - use 13 bits for -counter instead of 12 bits. - -Use only 12 bits for inside temperature in acurite driver when decoding -for 02032 stations. +Changes to the AcuRite driver include: + - The AcuRite driver now reports partial packets as soon as it gets them + instead of retaining data until it can report a complete packet + - Improved timing algorithm for AcuRite data. Thanks to Brett Warden. + - Added acurite log entries to logwatch script. Thanks to Andy. + - Prevent negative rainfall amounts in acurite driver by detecting + counter wraparound + - Use 13 bits for rain counter instead of 12 bits + - Use only 12 bits for inside temperature in acurite driver when decoding + for 02032 stations 3.1.0 02/05/15