From bcaadf96f52b2737f977fb3ca06fd05ef72040b2 Mon Sep 17 00:00:00 2001 From: Matthew Wall Date: Wed, 4 Dec 2013 00:16:27 +0000 Subject: [PATCH] fixed ws23xx polling interval bug --- bin/weewx/drivers/ws23xx.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/bin/weewx/drivers/ws23xx.py b/bin/weewx/drivers/ws23xx.py index 8725f2fd..5fb938f7 100644 --- a/bin/weewx/drivers/ws23xx.py +++ b/bin/weewx/drivers/ws23xx.py @@ -137,7 +137,7 @@ import weeutil.weeutil import weewx.abstractstation import weewx.wxformulas -DRIVER_VERSION = '0.9' +DRIVER_VERSION = '0.10' DEFAULT_PORT = '/dev/ttyUSB0' def logmsg(dst, msg): @@ -267,6 +267,7 @@ class WS23xx(weewx.abstractstation.AbstractStation): """ self._last_rain = None self._last_cn = None + self._poll_wait = 60 self.altitude = stn_dict['altitude'] self.port = stn_dict.get('port', DEFAULT_PORT) @@ -282,6 +283,7 @@ class WS23xx(weewx.abstractstation.AbstractStation): self.max_tries = int(stn_dict.get('max_tries', 5)) self.retry_wait = int(stn_dict.get('retry_wait', 30)) + loginf('driver version is %s' % DRIVER_VERSION) loginf('serial port is %s' % self.port) loginf('pressure offset is %s' % self.pressure_offset) loginf('polling interval is %s' % self.polling_interval) @@ -314,7 +316,6 @@ class WS23xx(weewx.abstractstation.AbstractStation): def genLoopPackets(self): ntries = 0 - wait = 60 while ntries < self.max_tries: ntries += 1 serial_port = None @@ -331,8 +332,19 @@ class WS23xx(weewx.abstractstation.AbstractStation): self._last_rain = packet['rainTotal'] ntries = 0 yield packet - wait = self.get_wait(wait, data['cn']) - time.sleep(wait) + + if self.polling_interval is not None: + self._poll_wait = self.polling_interval + if data['cn'] != self._last_cn: + conn_info = get_conn_info(data['cn']) + loginf("connection changed from %s to %s" % + (get_conn_info(self._last_cn)[0], conn_info[0])) + self._last_cn = data['cn'] + if self.polling_interval is None: + loginf("using %s second polling interval for %s connection" % + (conn_info[1], conn_info[0])) + self._poll_wait = conn_info[1] + time.sleep(self._poll_wait) except Exception, e: logerr("Failed attempt %d of %d to get LOOP data: %s" % (ntries, self.max_tries, e)) @@ -441,20 +453,6 @@ class WS23xx(weewx.abstractstation.AbstractStation): serial_port.close() serial_port = None - def get_wait(self, wait, conn): - if self.polling_interval is not None: - wait = self.polling_interval - if conn != self._last_cn: - loginf("connection changed from %s to %s" % - (get_conn_info(self._last_cn)[0], get_conn_info(conn)[0])) - if self.polling_interval is None: - conn_info = get_conn_info(conn) - loginf("using %s second polling interval for %s connection" % - (conn_info[1], conn_info[0])) - wait = conn_info[1] - self._last_cn = conn - return wait - # ids for current weather conditions and connection type SENSOR_IDS = [