Software architecture

This page is part of my Home Automation project.

The content is out of date at the monent.

The software has database centric architecture. Database is the key mechanism to exchange data in between lower layer (sensors and actuators) and upper layer (user interfaces and control logic). Each daemon and server is a separate process, which can be dynamically started or stopped without affecting the function of other processes.
Software architecture There are two different kind of database: * RAM file system resident MemDB for volatile data * Flash file system resident FlashDB for permanent configuration data Use of memory database increases performance and prevents flash disk wearing. There are two limitations with MemDB: i) Size of memory disk is limited by the availability of physical memory, and ii) data is not preserved over power outages. Due to that, there exists separate Logging daemon that periodically stores volatile data into physical flash file and cleans up the MemDB. FlashDB stores configuration data and permanent mappings between elements. Sensor readings and similar continuously changing data provided by bus daemons is stored in the MemDB. ==== Database ====
Database structure <del> MemDB is the primary data exchange database. It contains two tables: Variable and Value. Each physical parameter, like sensor reading, actuator target value, etc. has one row in Variable table defining properties of the variable. Each variable may have several values, separated with timestamp. Current value is the one with latest timestamp. Different variable types have different semantics from different roles perspective: ^ Type ^ Daemon ^ Server ^ | Sensor | Write only | Read only | | Actuator | Read only | Read-write | | Alarm | Write only | Read only | | Coil | Read-write | Read-write | Table Parameter in FlashDB provides mappings from physical parameter to logical parameter. For example, for each physical sensor, there may be one or more logical sensors, with different parameter settings. Parameter Group enables defining logical groups of parameters. Example:
Sensor Outdoor Air Temperature of ventilation unit may simultaneously belong to both ventilation measurements group and outdoor weather measurements group.

Initialization

RamDB is located in RAM file system, thus all date is lost each time system boots. Due to that database needs to be re-generated during each boot. There are bunch of scripts that create the database. /etc/rc3.d/S80ha/etc/init.d/ha.sh <file> #!/bin/sh PATH=/usr/local/bin . /lib/lsb/init-functions case “$1” in start) createdb.sh ;; *) ;; esac </file> /usr/local/bin/createdb.sh <file> #!/bin/bash PATH=/bin:/sbin:/usr/bin:/usr/sbin DB=/lib/init/rw/haram.db SQL=/usr/local/share/ha/ramdb.sql if [ -e ${DB} ]; then rm ${DB} fi echo “.exit” | sqlite3 -init ${SQL} ${DB} </file> /usr/local/share/ha/ramdb.sql <file> CREATE TABLE Variable ( VarID INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL, Device TEXT, Bus TEXT, Type TEXT NOT NULL, Quantity NOT NULL, Unit NOT NULL ); CREATE TABLE Value ( VarID INTEGER NOT NULL, Value REAL NOT NULL, Timestamp TIMESTAMP DEFAULT (datetime('now','localtime')), FOREIGNKEY VarID REFERENCES Variable(VarID) ); </file>