One further thing re rain and fileparse. The fileparse driver is very
basic, it essentially reads data from a text file, if required maps that
data to WeeWX field names and emits the data in a loop packet. Since WeeWX
uses per-period rain data the rain data in the fileparse data file must be
per-period. This works fine if the generation of the data file and the
polling of the data file by the fileparse driver remain in perfect sync;
however, if they should vary for any reason and, say, the data file is
updated before the fileparse driver reads the data file, rain data can be
missed. Continuous obs such as temperature, humidity etc are not effected
in the same manner due to their continuous nature.The way around this rain
limitation is to have the fileparse driver handle cumulative rain data.
I've submitted a PR with the necessary changes, we will see how that goes
for inclusion in the 4.1, but in the meantime you might want to revert to
your cumulative rain data and try with the attached modified fileparse
driver which will handle cumulative rain data. All you need to is replace
your existing fileparse.py with the attached version and under [FileParse]
in weewx.conf add the following setting:
[FileParse]
....
cumulative_rain = true
Then it is just a case of restarting WeeWX. Use of cumulative rain data can
be disabled by deleting the cumulative_rain setting or setting it to false.
Gary
On Wednesday, 13 May 2020 08:06:16 UTC+10, Ryan Stasel wrote:
>
> well that's unfortunate. I don't see a way to get that info out of
> meteobridge (such that it is per 30 seconds).
>
> hmm. suppose I could have the PHP compare previous and current value, and
> zero it out if it's equal to previous version.
>
> Open to other thoughts.
>
> On Tuesday, May 12, 2020 at 2:44:43 PM UTC-7, gjr80 wrote:
>>
>> WeeWX rainfall is a per period (loop or archive) value rather than as
>> cumulative rainfall. The fileparse driver is very basic and simply saves
>> the rain value from the source file in the WeeWX rain field. So fileparse
>> needs a file with a per period value. Other drivers calculate per period
>> rain from successive rain values, unfortunately fileparse does not.
>>
>> Gary
>>
>
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/34e16da9-4761-450a-97ca-f4a0d586b8b2%40googlegroups.com.
#!/usr/bin/python
#
# Copyright 2014 Matthew Wall
#
# weewx driver that reads data from a file
#
# This program is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation, either version 3 of the License, or any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.
#
# See http://www.gnu.org/licenses/
# This driver will read data from a file. Each line of the file is a
# name=value pair, for example:
#
# temperature=50
# humidity=54
# in_temperature=75
#
# The units must be in the weewx.US unit system:
# degree_F, inHg, inch, inch_per_hour, mile_per_hour
#
# To use this driver, put this file in the weewx user directory, then make
# the following changes to weewx.conf:
#
# [Station]
# station_type = FileParse
# [FileParse]
# poll_interval = 2 # number of seconds
# path = /var/tmp/wxdata # location of data file
# driver = user.fileparse
#
# If WeeWX field rain is to be derived from a cumulative total, add the option
# cumulative_rain under [FileParse] as follows:
#
# [FileParse]
# ...
# cumulative_rain = true # true if rain is derived from a cumulative
# # value, otherwise false or omit setting
#
# If the variables in the file have names different from those in the database
# schema, then create a mapping section called label_map. This will map the
# variables in the file to variables in the database columns. For example:
#
# [FileParse]
# ...
# [[label_map]]
# temp = outTemp
# humi = outHumidity
# in_temp = inTemp
# in_humid = inHumidity
from __future__ import with_statement
import logging
import time
import weewx.drivers
import weewx.wxformulas
from weeutil.weeutil import tobool
DRIVER_NAME = 'FileParse'
DRIVER_VERSION = "0.8"
log = logging.getLogger(__name__)
def _get_as_float(d, s):
v = None
if s in d:
try:
v = float(d[s])
except ValueError as e:
log.error("cannot read value for '%s': %s" % (s, e))
return v
def loader(config_dict, engine):
return FileParseDriver(**config_dict[DRIVER_NAME])
class FileParseDriver(weewx.drivers.AbstractDevice):
"""weewx driver that reads data from a file"""
def __init__(self, **stn_dict):
# where to find the data file
self.path = stn_dict.get('path', '/var/tmp/wxdata')
# how often to poll the weather data file, seconds
self.poll_interval = float(stn_dict.get('poll_interval', 2.5))
# mapping from variable names to weewx names
self.label_map = stn_dict.get('label_map', {})
# is the WeeWX rain field to be derived from a cumulative value or is
# it already a per-period value
self.cumulative_rain = tobool(stn_dict.get('cumulative_rain', False))
log.info("Data file is %s" % self.path)
log.info("Polling interval is %s" % self.poll_interval)
log.info('Label map is %s' % self.label_map)
if self.cumulative_rain:
log.info("'rain' will be calculated from a cumulative value")
def genLoopPackets(self):
last_rain = None
while True:
# read whatever values we can get from the file
data = {}
try:
with open(self.path) as f:
for line in f:
eq_index = line.find('=')
name = line[:eq_index].strip()
value = line[eq_index + 1:].strip()
data[name] = value
except Exception as e:
log.error("read failed: %s" % e)
# map the data into a weewx loop packet
_packet = {'dateTime': int(time.time() + 0.5),
'usUnits': weewx.US}
for vname in data:
_packet[self.label_map.get(vname, vname)] = _get_as_float(data, vname)
# if rain is calculated from a cumulative value the packet rain
# field is the difference between the current cumulative rain value
# and the last cumulative rain value
if self.cumulative_rain and 'rain' in _packet:
this_rain = _packet['rain']
_packet['rain'] = weewx.wxformulas.calculate_rain(_packet['rain'],
last_rain)
last_rain = this_rain
yield _packet
time.sleep(self.poll_interval)
@property
def hardware_name(self):
return "FileParse"
# To test this driver, run it directly as follows:
# PYTHONPATH=/home/weewx/bin python /home/weewx/bin/user/fileparse.py
if __name__ == "__main__":
import weeutil.weeutil
import weeutil.logger
import weewx
weewx.debug = 1
weeutil.logger.setup('fileparse', {})
driver = FileParseDriver()
for packet in driver.genLoopPackets():
print(weeutil.weeutil.timestamp_to_string(packet['dateTime']), packet)