Monitoring My Central Heating Boiler
An introduction to the whole boiler monitoring project is explained here.
If you have read the page at the link above, you'll now know that the boiler monitoring system was logging on-and-off events, measuring temperatures on the boiler and generating graphs using a CGI program using a PC and Velleman K8055 I/O card. This page describes what I had to do to replicate the system but using a Pi and a PiFace I/O card instead.
The hardware and software that make up the entire system is described below. There is also a process that takes you step-by-step through the commands to download the programs and run them.
Since I was replacing the PC with a Pi, I have only listed the Pi-specific hardware here because the relay unit remains the same:
- Model B Pi
- Piface Digital interface card
- Dallas Semiconductor (Maxim) DS9490R 1-Wire USB adapter
- Dallas Semiconductor (Maxim) DS18S20 1-Wire thermometers
The block diagram below shows the general arrangement of the hardware. An interface to a GSM modem for sending text alerts may be added at a later date.
The Raspberry Pi programs comprise:
- Event logger - communicates with a PiFace Digital card and records the status of three inputs: mains power, pump running and burner firing. It writes event data to a daily file.
- Temperature logger - communicates with the 1-Wire network and records the temperatures at various points on the boiler and writes the data to a daily file.
- CGI program - this program is invoked by Apache and generates a calendar and displays graphs of boiler events and temperatures.
The programs were all originally written in C for Windows and ran on a Dell GX11 PC running Windows/2000 Server. The original event logger communicated with a Velleman K8055 USB interface card but since the programming was completely different to the PiFace, I rewrote most of the program.
The original 1-Wire temperature logger used the DalSemi DLLs but the OWFS software hides all the complexity and so this program was mostly rewritten except for the I/O sections.
The CGI program is the most complex because it generates its own calendar and in-line SVG for the bar chart and graph but turned out to be the easiest to convert with only a couple of coding changes. These changes were replacing function definitions and calls to _stat() (Windows) with statfs() (Linux) for file system statistics. I also made a few corrections to the code that read in character strings.
The structure of the filesystem is shown here. Standard Linux and Apache directories are shown in yellow; custom directories in blue. Everything goes under /1-wire with source files, events data and temperature data going into their own sub-directories along with the daemons that collect the data.
I have used standard installations of Apache and OWFS on a version of the OS with PiFace already installed. There's more information about the PiFace and its pre-loaded disk image here.
SET UP PROCESS
Create the directory structure:
Download and compile the programs:
wget http://www.noveldevices.co.uk/rpdl/logger.c -O /1-wire/src/logger.c
wget http://www.noveldevices.co.uk/rpdl/1-wire.c -O /1-wire/src/1-wire.c
wget http://www.noveldevices.co.uk/rpdl/server.c -O /1-wire/src/server.c
gcc -L/usr/local/lib -lpiface-1.0 -o /1-wire/events/logger /1-wire/src/logger.c -lm
gcc -L/usr/local/lib -o /1-wire/temperatures/1-wire /1-wire/src/1-wire.c -lm
gcc -L/usr/local/lib -o /usr/lib/cgi-bin/server /1-wire/src/server.c -lm
Download some example configuration files and a CSS file:
wget http://www.noveldevices.co.uk/rpdl/1-wire.conf -O /1-wire/temperatures/1-wire.conf
wget http://www.noveldevices.co.uk/rpdl/server.conf -O /usr/lib/cgi-bin/server.conf
wget http://www.noveldevices.co.uk/rpdl/boiler.css -O /var/www/boiler.css
The 1-wire.conf file contains configuration information for the 1-wire program and for the CGI program that creates the graphs. Each entry is described below (the actual order of records does not matter):
- [Interval]=n - polling interval in seconds, but see note below
- [DataDirectory]=directory where you want data files to be written (with a trailing /)
- For each sensor: [DevicePath]=full-path-to-OWFS-directory-(with-trailing-/) plot-colour sensor-description
plot-colour is a standard web colour as #RRGGBB, #RGB CSS colour.
sensor-description is a short phrase that should appear on the temperature plot
The polling interval can be any number of seconds but you need to bear in mind that OWFS takes typically two seconds to obtain the temperature from each sensor. The program re-calculates the actual interval time based on the start and finish time of the data collection process so that the collection start times do not drift.
An example 1-wire.conf file is shown below:
[Interval]=600 [DataDirectory]=/1-wire/temperatures/ [DevicePath]=/mnt/1wire/10.207F3D000000/ #ff0000 Sensor 1
The server.conf file contains configuration information for the CGI program and for the CGI program that creates the graphs. Each entry is described below (the actual order of records does not matter):
- [CGIServer]=full URL of CGI server and path and CGI executable
- [WebServer]=full URL of web server that will serve images and HTML
- [DataFiles]=full local path to events directory
- [1-WireConfig]=full local path to 1-Wire configuration file
- [PlotType]=n - use 2 for now
- [ChannelsToPlot]=n - the number of event channels to plot (how many event inputs you have)
- [ChannelsRecorded]=n - the number of event channels actually being recorded (8 for PiFace)
- [Graphpaper]=n - 0 for no graph paper, 1 for graph paper
- [DiagFlag]=n - 0 for minimal comments in HTML, 1 for more
- [CalendarType]=n - 0 for plain table calendar, 1 for image-based calendar
- [GraphSize]=width,height - values in pixels
- [GraphMargins]=top,right,bottom,left - values in pixels
- [Channel-n-colour]=#RRGGBB, #RGB or CSS colour to be used on events graph for channel n
- [Channel-n-title]=description - a description of the event being displayed for channel n
An example server.conf file is shown below:
[CGIServer]=http://10.34.220.164/cgi-bin/server [WebServer]=http://10.34.220.164/ [DataFiles]=/1-wire/events/ [TempFiles]=/1-wire/temperatures/ [1-WireConfig]=/1-wire/temperatures/1-wire.conf [PlotType]=2 [ChannelsToPlot]=3 [ChannelsRecorded]=8 [GraphPaper]=1 [DiagFlag]=1 [CalendarType]=1 [GraphSize]=800,360 [GraphMargins]=40,50,50,150 [Channel-1-colour]=red [Channel-2-colour]=blue [Channel-3-colour]=green [Channel-1-title]=Pump running [Channel-2-title]=Boiler on [Channel-3-title]=Mains supply
STARTING THE DATA COLLECTION PROGRAMS
OWFS is a prerequisite and must be started first. Plug in your DS9490R USB adapter and 1-Wire LAN and then run the following program:
sudo /opt/owfs/bin/owfs --allow_other -u -m /mnt/1wire
DEFAULT: ow_usb_msg.c:(295) Opened USB DS9490 bus master at 1:5.
DEFAULT: ow_usb_cycle.c(191) Set DS9490 1:5 unique id to 81 57 C7 30 00 00 00 3A
You should now start the event and temperature loggers:
sudo ./logger >logfile &
sudo ./1-wire >logfile &
Each logger runs in its own directory and writes its data to a new file each day. Console output should be written to a logfile to assist in debugging.
You should now enter the URL of your CGI program in a browser:
To understand how OWFS works, please visit owfs.org. OWFS creates a file system structure under /mnt and populates it with the 1-Wire device attributes and values as files. For more information, have a look at the set up process here.