Skip to content

Commit

Permalink
Make live data loop more rugged
Browse files Browse the repository at this point in the history
It was possible to get into a state where every pointer change was being
detected late and it never woke up early enough to set the station clock
and start logging data. This change should stop that happening.

Signed-off-by: Jim Easterbrook <jim@jim-easterbrook.me.uk>
  • Loading branch information
jim-easterbrook committed Jul 17, 2015
1 parent 328747c commit 84be710
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
19 changes: 14 additions & 5 deletions src/pywws/WeatherStation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# pywws - Python software for USB Wireless Weather Stations
# http://github.com/jim-easterbrook/pywws
# Copyright (C) 2008-15 Jim Easterbrook jim@jim-easterbrook.me.uk
# Copyright (C) 2008-15 pywws contributors

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down Expand Up @@ -411,6 +411,7 @@ def live_data(self, logged_only=False):
# due. (During initialisation we get data every half second
# anyway.)
read_period = self.get_fixed_block(['read_period'])
self.logger.debug('read period %d', read_period)
log_interval = float(read_period * 60)
live_interval = 48.0
old_ptr = self.current_pos()
Expand Down Expand Up @@ -496,10 +497,18 @@ def live_data(self, logged_only=False):
if ptr_time - last_ptr_time < self.margin:
# pointer has just changed, so definitely at a logging time
self._station_clock.set_clock(ptr_time)
elif next_log and ptr_time < next_log - self.margin:
self.logger.warning(
'live_data lost log sync %g', ptr_time - next_log)
self._station_clock.invalidate()
elif next_log:
if ptr_time < next_log - self.margin:
self.logger.warning(
'live_data lost log sync %g', ptr_time - next_log)
self._station_clock.invalidate()
else:
self.logger.warning('missed ptr change time')
last_log -= live_interval
if read_period > new_data['delay']:
read_period = new_data['delay']
self.logger.warning('reset read period %d', read_period)
log_interval = float(read_period * 60)
next_log = self._station_clock.nearest(ptr_time)
if next_log:
result = dict(new_data)
Expand Down
6 changes: 3 additions & 3 deletions src/pywws/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__version__ = '15.07.0.dev1304'
_release = '1304'
_commit = 'c851b94'
__version__ = '15.07.0.dev1305'
_release = '1305'
_commit = '328747c'

0 comments on commit 84be710

Please sign in to comment.