Hi all,
I have a custom sump pump station that I integrated with weeWX using
mod_python. The station pushes archive records regularly over HTTP into
weeWX. I'm not sure if anyone else is doing this and it's been running
great for about a month so I thought I'd post the details.
Note that this gets down and dirty with some weeWX Python assumptions. This
will void your warranty :)
The sump pump station has two attached sensors: "level" (water level) and
"onticks" (milliseconds pump energized). The station itself is an Arduino
board with WiFi (AdaFruit Feather M0 with WINC1500). The Arduino code was
already doing 5 minute aggregation of the sensor data so I didn't want to
go the normal route with LOOP packets and an extension. I basically already
had archive records, I just wanted to add them as simply as possible.
After the following procedure, doing an HTTP GET like
/mp/post_weewx.py/sump_record?interval=5&level=2000&onticks=0 will add an
archive record to a sump.sdb SQLite database. The database file and tables
will be created if necessary. All standard weeWx processing gets done (I
think) and all standard tagging is then available in reports (I think).
1) install mod_python for Apache (note that mod_wsgi seems to have replaced
mod_python but mod_python seems simpler and works fine)
2) create a subdirectory "mp" off the Apache DocumentRoot
3) create mp/.htaccess with the contents:
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
PythonPath "sys.path+['/usr/share/weewx']"
3) create mp/post_weewx.py with the contents:
import time
import configobj
import weewx.manager
def sump_record(req, interval, level, onticks):
config_dict = configobj.ConfigObj('/etc/weewx/weewx.conf',
file_error=True)
dbb = weewx.manager.DBBinder(config_dict)
mgr = dbb.get_manager('sump_binding', True)
rec = dict()
rec['dateTime'] = int(time.time())
rec['usUnits'] = 1
rec['interval'] = int(interval)
rec['level'] = int(level)
rec['onticks'] = int(onticks)
mgr.addRecord(rec)
req.content_type = 'text/plain'
return 'Success'
4) modify weewx.conf:
[DataBindings]
[[sump_binding]]
database = sump_sqlite
table_name = archive
manager = weewx.manager.DaySummaryManager
[[[schema]]]
dateTime = INTEGER NOT NULL PRIMARY KEY
usUnits = INTEGER NOT NULL
interval = INTEGER NOT NULL
level = INTEGER
onticks = INTEGER
[Databases]
[[sump_sqlite]]
database_type = SQLite
database_name = sump.sdb
5) modify the standard report to use the new tags, some examples:
[[[daysumplevel]]]
data_binding = sump_binding
[[[[level]]]]
label = Sump Level
[[[daysumpon]]]
data_binding = sump_binding
plot_type = bar
[[[[onticks]]]]
aggregate_type = sum
aggregate_interval = 1800
label = Sump Activity (30-min total)
6) sort out write permissions to the database file, easiest is to make
/var/lib/weewx writable by all
--
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.