I'm still lost on how to merge data from 2 stations

303 views
Skip to first unread message

crich...@gmail.com

unread,
Feb 7, 2017, 9:22:56 AM2/7/17
to weewx-development
I'm still working out how to integrate my alternate data source + a weather station into weewx.  The one LaCrosse station is already running with weewx-interceptor just fine.  This other thing monitors AC current for my sump pumps, dehumidifier, circ fan, furnace, and its own power supply.  The point is to log when things turn on and off, or more precisely, determine if they have failed. It's run with some custom hardware I made on a Pi3.  All this is in my crawl space. I've looked through the customization guide, and I think I've worked out the kinds of values I want to use (thank Tom).  Where I'm lost is how to have a single weewx instance listen to two drivers, or how to have one driver consume data from the two stations.  Looking at weewx-interceptor and the weewx-observer (pretty close to what I need for the monitor).  In interceptor, could a second listener thread be started that uses the same queue?  From the customization guide for Services, the electric meter example was read as an extra service.  Is that the same idea as running two drivers?
Is there a better idea?

Thx, Chris

Thomas Keffer

unread,
Feb 7, 2017, 9:56:15 AM2/7/17
to crich...@gmail.com, weewx-development
There are two general strategies:

1. Run multiple instances of weewx on one computer, then combine the results in the reporting stage. Each will have its own device driver --- one for the LaCrosse station, one for the AC monitor. This method will result in two independent databases. They can then be queried for the final reports.

2. Run one instance of weewx, then augments the data stream coming off the device driver. This requires writing a custom weewx service that adds on to the data coming off the one device driver. For example, you could run a regular weewx instance that monitors your LaCrosse weather station. Then the custom service would add you extra data onto the packets coming out of the LaCrosse. Generally, your service should run and monitor a separate thread that talks to your AC monitor. This way, you won't slow down the main thread should the AC monitor block. This is the method documented in the Customizing Guide Adding a new observation type, although not very well. The new V3.7 documentation (to come out Real Soon Now) does a slightly better job of documenting this.

Hope this helps.

-tk


mwall

unread,
Feb 8, 2017, 7:38:51 AM2/8/17
to weewx-development
the wiki has an example of how to do option 2 using file parsing:

https://github.com/weewx/weewx/wiki/add-sensor

the wiki also has an example of how to do option 2 using a separate thread:

https://github.com/weewx/weewx/wiki/multi-threaded-service

crich...@gmail.com

unread,
Feb 8, 2017, 2:59:01 PM2/8/17
to weewx-development, crich...@gmail.com
OK, so I'm maybe taking too many steps at once, but I tried to add some observations types to the DB schema for a non-existent database (starting fresh using mwall's observer driver, plus my mods).  On it's own, the driver starts up.  I added the code from the 'Add a new type to the archive database' instructions just before __main__ block in the driver.
import schemas.wview
schema_with_devices = schemas.wview.schema + [('pump1',   'REAL')]
schema_with_devices = schema_with_devices  + [('pump2',   'REAL')]
schema_with_devices = schema_with_devices  + [('furnace1' 'REAL')]

I updated the wx_binding with: schema = user.devices.schema_with_devices, and tried this: bin/wee_database weewx.devices.conf --reconfigure
It failed for:
  File "/home/weewx/bin/weewx/manager.py", line 954, in get_manager_dict_from_config
    manager_dict['schema'] = weeutil.weeutil._get_object(schema_name)
  File "/home/weewx/bin/weeutil/weeutil.py", line 1015, in _get_object
 ImportError: No module named devices

So, are the schema extensions adding columns of type REAL, or something different?  I ask because in the example is this:
schema = user.electricity.schema_with_electricity
where electricity is the module name, but I have no idea where electricity is being made a module name other than in the schema extensions, and if those are just columns, I'm lost, again.  I realize this is more a python problem.  Oh, there's one more reference to electricity as an event record, but again, that doesn't sound like a module either.  I resolved this particular issue by changing to schema = user.observer.schema_with_devices, but the driver fails to load as below.

Backing away a bit and using the stock Observer driver still doesn't load.  
These are the only config differences (sorry about the font) relative to the Intercepter config that's working:
router.chaos.home_/home/weewx> sdiff -s -W -w 135 weewx.devices.conf weewx.weather.conf | more
debug = 1                                                          |    debug = 0
    station_type = Observer                                        |        station_type = Interceptor
    SKIN_ROOT = skins.devices                                      |        SKIN_ROOT = skins.weather
    HTML_ROOT = public_html.devices                                |        HTML_ROOT = public_html.weather
    #   schema = user.observer.schema_with_devices                 <
        SQLITE_ROOT = %(WEEWX_ROOT)s/archive.devices               |            SQLITE_ROOT = %(WEEWX_ROOT)s/archive.weather
[Observer]                                                         |    [Interceptor]
    driver = user.observer                                         |        driver = user.interceptor
    port   = 6943                                                  |        port   = 8080
    # How often to poll the device, in seconds                     |        #
    poll_interval = 150                                            |        # Specify the hardware device to capture.  Options include:
                                                                   >        device_type = lacrosse-bridge

Feb  8 11:46:21 router weewx[32575]: engine: Initializing weewx version 3.6.2
Feb  8 11:46:21 router weewx[32575]: engine: Using Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37) #012[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)]
Feb  8 11:46:21 router weewx[32575]: engine: Platform Linux-2.6.32-573.7.1.el6.x86_64-x86_64-with-centos-6.7-Final
Feb  8 11:46:21 router weewx[32575]: engine: Using configuration file /home/weewx/weewx.devices.conf
Feb  8 11:46:21 router weewx[32575]: engine: Loading station type Observer (user.observer)
Feb  8 11:46:21 router weewx[32575]: import of driver failed: __init__() got an unexpected keyword argument 'driver' (<type 'exceptions.TypeError'>)
Feb  8 11:46:21 router weewx[32575]: engine: Unable to load driver: __init__() got an unexpected keyword argument 'driver'
Feb  8 11:46:21 router weewx[32575]:     ****  Exiting...

Trying to create the DB by hand using a copy of the working config, and it also doesn't work.  The other instance is still running fine from the same area, so I don't think
I hosed up my weewx install.

router.chaos.home_/home/weewx> !sd
sdiff -s -W -w 135 weewx.devices.conf weewx.weather.conf | more
    SKIN_ROOT = skins.devices                                      |        SKIN_ROOT = skins.weather
    HTML_ROOT = public_html.devices                                |        HTML_ROOT = public_html.weather
        SQLITE_ROOT = %(WEEWX_ROOT)s/archive.devices               |            SQLITE_ROOT = %(WEEWX_ROOT)s/archive.weather

router.chaos.home_/home/weewx> bin/wee_database --config=weewx.devices.conf --create-archive
Using configuration file weewx.devices.conf
Using database binding 'wx_binding', which is bound to database 'archive_sqlite'
Traceback (most recent call last):
  File "bin/wee_database", line 453, in <module>
    main()
  File "bin/wee_database", line 156, in main
    createMainDatabase(config_dict, db_binding)
  File "bin/wee_database", line 179, in createMainDatabase
    with weewx.manager.open_manager_with_config(config_dict, db_binding) as dbmanager:
  File "/home/weewx/bin/weewx/manager.py", line 984, in open_manager_with_config
    return open_manager(manager_dict, initialize)
  File "/home/weewx/bin/weewx/manager.py", line 976, in open_manager
    manager_dict['table_name'])
  File "/home/weewx/bin/weewx/manager.py", line 102, in open
    dbmanager = cls(connection, table_name)
  File "/home/weewx/bin/weewx/manager.py", line 1109, in __init__
    super(DaySummaryManager, self).__init__(connection, table_name, schema)
  File "/home/weewx/bin/weewx/manager.py", line 70, in __init__
    self.sqlkeys = self.connection.columnsOf(self.table_name)
  File "/home/weewx/bin/weedb/sqlite.py", line 159, in columnsOf
    raise weedb.ProgrammingError("No such table %s" % table)
weedb.ProgrammingError: No such table archive

Thx, Chris

crich...@gmail.com

unread,
Feb 8, 2017, 8:28:23 PM2/8/17
to weewx-development
I think I found the issue with loading the observer driver.
This was:
def loader(config_dict, engine):
    return Observer(**config_dict[DRIVER_NAME])

Changing it to:
def loader(config_dict, engine):
    return ObserverDriver(**config_dict[DRIVER_NAME])

enabled weewx to start up.
Reply all
Reply to author
Forward
0 new messages