Below is the entire driver. I was using the archive database names which as far as I can see using Sqliteman have those names with no caps. It must mean that the archive and loop data don't have the same names. I change it easily enough. I see fileparse.py does have outTemp and outHumidity etc but where does one find all the labels?
# # based on FileParse.py by Matthew Wall and also a driver by Neville Davis # https://www.dropbox.com/s/a0fq254dwlpgm0l/piweather.py?dl=0 # # Driver for the Raspberry Pi3 which has the RFM69 # which takes information from the Davis ISS # and BME280 modules # # # # *args and **kwargs https://pythontips.com/2013/08/04/args-and-kwargs-in-python-explained/ # # # Create a file in the user directory, say mydriver.py. This file will contain the driver class as well as any hardware-specific code. # Do not put it in the weewx/drivers directory or it will be deleted when you upgrade weeWX. # file driver.py should go to the user directory. In your case that will be: /usr/share/weewx/user. # Inherit from the abstract base class weewx.drivers.AbstractDevice. Try to implement as many of its methods as you can. # At the very minimum, you must implement the first three methods, loader, hardware_name, and genLoopPackets. # loader # This is a factory function that returns an instance of your driver. It has two arguments: the configuration dictionary, and a reference to the weeWX engine. # hardware_name # Return a string with a short nickname for the hardware, such as "ACME X90" # genLoopPackets # This should be a generator function that yields loop packets, one after another. Don't worry about stopping it: the engine will do this when an archive record is due. # A "loop packet" is a dictionary. At the very minimum it must contain keys for the observation time and for the units used within the packet. # # The fileparse driver is perhaps the most simple example of a weeWX driver. It reads name-value pairs from a file and uses the values as sensor 'readings'. # The code is located in extensions/fileparse/bin/user/fileparse.py # # A couple of observation types are tricky. In particular, rain. # Generally, weeWX expects to see a packet with the amount of rain that fell in that packet period included as observation rain. # It then sums up all the values to get the total rainfall and emits that in the archive record. # Davis ISS sends bucket tipa, 1 tip = 0.01", only goes to 127 0x7f before it goes to 0 from __future__ import with_statement import syslog import time import weewx.drivers DRIVER_NAME = 'mypiweewxdriver' DRIVER_VERSION = "0.0" def logmsg(dst, msg): syslog.syslog(dst, 'fileparse: %s' % msg) def logdbg(msg): logmsg(syslog.LOG_DEBUG, msg) def loginf(msg): logmsg(syslog.LOG_INFO, msg) def logerr(msg): logmsg(syslog.LOG_ERR, msg) def _get_as_float(d, s): v = None if s in d: try: v = float(d[s]) except ValueError, e: logerr("cannot read value for '%s': %s" % (s, e)) return v def loader(config_dict, engine): return MyPiweewxDriver(**config_dict[DRIVER_NAME]) # To define the hardware_name it appears it has to go within a class # Python classes provide all the standard features of Object Oriented Programming: # the class inheritance mechanism allows multiple base classes, # a derived class can override any methods of its base class or classes, # and a method can call the method of a base class with the same name. # Objects can contain arbitrary amounts and kinds of data. # As is true for modules, classes partake of the dynamic nature of Python: they are created at runtime, and can be modified further after creation. # # This class has an initialization and then a genLoopPackets # class MyPiweewxDriver(weewx.drivers.AbstractDevice): """weewx driver that reads data from Davis ISS""" def __init__(self, **stn_dict): # where to find the data file self.path = stn_dict.get('path', '/var/ramdisk/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', {}) loginf("data file is %s" % self.path) loginf("polling interval is %s" % self.poll_interval) loginf('label map is %s' % self.label_map) def genLoopPackets(self): while True: #read whatever values we can get from the file start_time = time.time() # Create Loop packet try: # If it does not open then DissData has not gotten a good packet from Davis ISS f = open('/var/ramdisk/wxdata', 'r') input = f.read() f.close() data = {} try: for line in input.splitlines(): eq_index = line.find('=') name = line[:eq_index].strip() value = line[eq_index + 1:].strip() data[name] = value except Exception, e: logerr("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) yield _packet sleep_time = (start_time - time.time()) + self.loop_interval if sleep_time > 0: time.sleep(sleep_time) except IOError, e: time.sleep(60) # sleep for a minute to let Dissdata get a packet @property def hardware_name(self): return "MyPiweewx" if __name__ == "__main__": import weeutil.weeutil station = MyPiweewxDriver() for packet in station.genLoopPackets(): print weeutil.weeutil.timestamp_to_string(packet['dateTime']), packet -- 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]. For more options, visit https://groups.google.com/d/optout.
