This is an old revision of the document!


EDA Daemon (edad)

This page is part of my Home Automation project.

This software collects data from Ventilation Unit (EDA) and stores it into a database for further use by building automation system. The software is specific to Enervent ventilation units and is expected to support following models: Pingvin, Pandion, Pelican, Pegasos, Pegasos XL, LTR-3, LTR-6, LTR-7, and LTR-7 XL. Currently tested only with Pingvin. Further models with EDA support may be supported as well.

Requirements:

Usage: edad <devicename> <databasefile>

devicename   = Name of the serial device having modbus adapter
               eg. /dev/ttyS0 or /dev/ttyUSB0
databasefile = name of the file hosting sqlite3 database
               default: /lib/init/rw/edad.db

The software acts as a slave in the modbus, and receives periodical register updates from ventilation unit. The software never writes to the bus anything.

The software creates two tables into the given database file: Temperature and Misc'. Table Temperature holds measured channels temperatures (Outdoor, Supply, Exhaust, and Waste). Table Misc holds miscallaneous readings (Exhaust humidity, Input efficiency, Output efficiency, Power). Each row in both tables has a timestamp.

Debian creates a ram disk /lib/init/rw by default. That disk is used to store database, in order to conserve flash disk. Other locations may be used if Flash wearing is not a problem. The edad does not take care of backup and restore of the ram database, thus that must be taken care by some other software.

If the database does not exists, it will be created, as well as tables inside the db. The daemon only inserts new rows into the tables, never deletes anything. Periodical cleaning of the database, in order to conserve ram memory (in case of ram disk resident database file), is responsibility of some other software.

Software architecture

The software is based on following libraries:

The software is executed in single main loop (single thread). mb_slave module is a wrapper to libmodbus library. Function call to modbus_receive is blocking, and returns once a modbus frame is received, or an error has occured. The mb_slave module inspects the reason of the return of the function call, and if it was because of “write multiple registers” (code 16), internal register bank is updated.

The main loop does required processing (unit transfer, filtering, etc) and stores interesting register values into two register banks: Temperatures [float] and Miscallaneous [unsigned integer]. The main loop has an interval counter, and once the pre-defined interval has passed, it will write data to the database via database wrapper module.

Build it

In Debian and derivatives, sqlite3 is available as package, and can be installed with package manager:

$ sudo aptitude install libsqlite3-dev 

At the moment of writing this page, libmodbus is not available as a standard package for debian, but must be build manually, as described at Linux modbus support page.

The software itself is has no fancy build and configuration system. Just simply extract the package, make it, and copy the binary wherever you want to:

$ tar xvzf eda.tgz
$ cd Enervent
$ make
$ cp edad /usr/local/bin
Init script

This instruction is specific to Debian 6.0 (Squeeze), and derivatives.

In order to run the daemon automatically after each reboot, place the following script to /etc/init.d/eda. The script expects that nacup copy of database file is stored in location /opt/BA/data/<year>/<month>/<day>/ and tries to restore it prior starting the daemon.

The script is copied from somewhere and needs to be finalized.

#!/bin/sh

### BEGIN INIT INFO
# Provides:          eda
# Required-Start:    
# Required-Stop:     
# Should-Start:      $portmap
# Should-Stop:       $portmap
# X-Start-Before:    nis
# X-Stop-After:      nis
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: Example initscript
# Description:       This file should be used to construct scripts to be
#                    placed in /etc/init.d.
### END INIT INFO


PATH=/usr/local/bin:$PATH
DB=/lib/init/rw/eda.db
DEV=/dev/ttyS0
DATA=/opt/BA/data

YEAR=`date '+%Y'`
MONTH=`date '+%m'`
DAY=`date '+%d'`

. /lib/lsb/init-functions

case "$1" in
    start)
        echo "Staring EDA daemon.."
        if [ -f $DATA/$YEAR/$MONTH/$DAY ]; then
                cp $DATA/$YEAR/$MONTH/$DAY/eda.db $DB 
        fi
        edad $DEV $DB &
        ;;
    *)
        ;;
esac

Modify the script according to your setup. Save it under /etc/init.d and run following command to enable it.

$ insser /etc/init.d/eda

Download

Version history:

0.1.1 2011-12-07 Fixed bug in number conversion with sub-zero temperatures.
0.1 2011-12-04 Initial draft. Does support receiving some data from modbus interface and storing it into database.

edad.1323439769.txt.gz · Last modified: 2011/12/09 16:09 by jap
Recent changes RSS feed CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki