Yep. That's a good solution. Do you have any recommendations for wiring in a baro sensor?
There are plenty of options for buying I2C barometers based on the Bosch BMP-280. I picked up a pack of five on Amazon for $10.88, and had to solder the header pins on them at that price. Tutorials for hooking sensors up to the Pi's I2C pins with a handful of Dupont cable jumpers are available in Google. I found someone's code that reads the sensor info and throws it into a file, which is not elegant but is easy to modify the weewx example file plugin to import.
https://github.com/weewx/weewx/wiki/Raspberry%20Pi%20weather%20station%20with%20i2C%20sensorsBringing in the data, I did it as a weewx data service. In the services section of weewx.conf:
data_services = user.i2c.i2cService
A weewx data service augments the default station's data, allowing you to insert external readings from another source into your observation loop packets. Exactly what we want to do to add the barometer readings, working around weewx's limits of only having one station hardware defined.
This is the butchery that I did on the text file input sample code, placed in /usr/share/weewx/user/i2c.py :
#!/usr/bin/python
#
# Portions Copyright 2014 Matthew Wall
# Portions taken from the pond.py example on the "add sensor" page on the weewx wiki, edited by Tom Keffer
#
# weewx service that reads data from a file as key value pairs and adds it to every loop packet
#
# This driver will read data from a file. Each line of the file is a
# name=value pair, for example:
#
# inTemp=50
# pressure=1009.4
# inHumidity=75
#
# The names must match the weewx database schema, but the schema can be extended for new fields
#
# The units must be in the weewx.US unit system:
# degree_F, inHg, inch, inch_per_hour, mile_per_hour
#
# Add this service to weewx.conf, then restart weewx
#[Engine]
#[[Services]]
# data_services = ..., user.i2c.i2cService
#
#
# 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/
import syslog
import weewx
from weewx.wxengine import StdService
class i2cService(StdService):
def __init__(self, engine, config_dict):
super(i2cService, self).__init__(engine, config_dict)
d = config_dict.get('i2cService', {})
self.filename = d.get('filename', '/var/www/html/weewx/wxdata.txt')
syslog.syslog(syslog.LOG_INFO, "i2c: using %s" % self.filename)
self.bind(weewx.NEW_LOOP_PACKET, self.read_file)
def read_file(self, event):
data= {}
try:
with open(self.filename) 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, e:
data['error'] = 1
# logerr("read failed: %s" % e)
for vname in data:
event.packet[vname] = float(data[vname])
Certainly not the cleanest or most elegant solution, but someone can clean it up and maybe even skip the file output/input step.
Since there is suddenly a market for a substitute Acu-Rite bridge, the ultimate goal should probably be to develop a pre-built Raspbian SD card image with everything pre-installed to run the SDR and weewx out of the box. I have no interest with following through, but will share my spaghetti on GitHub if someone wants to use it as a baseline and clean it up.....