This device allows you to control the heating (or any other device) by calling in and using an interactive voice menu. In case of a power loss the last state will be restored as soon as the power is back. The software is build to survive unexpected power losses.
The heart of the system is a Raspberry pi with a custom hat to provide 12V to an external relay. On this Raspberry pi a custom embedded linux is used to to control the 12V via a small shell script. It connects via ethernet to the a SIP server (e.g. a fritzbox router or your isp). The heavy lifting for the SIP connection and the voice menu is done by asterisk, which uses the already mentioned shell script to switch a gpio pin. The linux system is build with buildroot and the hole image image is less than 200MB and boots in a few seconds.
The linux system on the raspberry pi is configured to use the micro sd card as read only storage. This should prevent damage on power failure. The only exception is a persitent partition, which is used to save the current state. This state will be restored in case of a power failure. The partition should also be safe from corruption due to the mount parameters and the infrequent writes.
Connect Power (5V via micro-USB and 12V), ethernet and the output to the relay. After bootup the device accepts incoming calls.
Call the device, wait until pickup and follow the voice instructions:
#
1
to turn the heating on, 2
to turn the heating off, 3
to get the status of the heatingAfter a timeout the caller will be disconnected automatically.
5V (micro USB)
|
v
+-----------------+ +----------------+ +----------+
| router / switch | SIP (over ethernet) | Raspberry Pi | 12V Switched | Relay of |
| e.g. fritzbox |<-------------------->| (with 12V hat) |------------->| heating |
+-----------------+ +----------------+ +----------+
^
|
12 V
The custom embedded system is based on buildroot. The behaviour at a call is controlled by Asterisk. There are two main configuration files:
/etc/asterisk/sip.conf
SIP server configuration/etc/asterisk/extensions.conf
Dialplan (phone menu, pin)The configuration files can be adjusted by changing the files of the overlay (br-external/board/raspberrypi-heating-control/rootfs-overlay
). Asterisk is configured to only use a minimal amount of modules. Modify /etc/asterisk/modules.conf
if necessary.
There is a watchdog script (/opt/heatingControl/asterisk_wdog
) that monitors the peers and registry and will restart asterisk in case of failures. It is automatically started at boot via /etc/init.d/S55asterisk_wdog
. You probably want to stop it to configure asterisk and start it after the finished configuration.
For maintenace and debugging it is possible to connect to the device via a serial connection (115200 8N1) or HDMI. The system is by default read-only. To modify the file system it has to be remounted (mount -o remount,rw /
). The login data is:
You can build the sd card image yourself by cross compiling it on your pc. Depending on your hardware configuration this may take a while. Simply follow these steps:
--recursive
to get buildroot submodule)cd software
)make BR2_EXTERNAL=$PWD/br-external -C buildroot raspberrypi23-heating-control_defconfig
make -C buildroot
buildroot/output/images/sdcard.img
to sd card (e.g. dd if=buildroot/output/images/sdcard.img of=/dev/mmcblk0 bs=1M && sync
)You don't need any special hardware for this. The raspberry pi will just toggle one of the GPIO PINs (see /opt/heatingControl/controlheating
for details).
The author of this project wants to switch a 12V relay and has designed a hat for this task. This hat is designed to take quite a bit of abuse like e.g. short circuit, reverse power, ESD etc. and can supply 5-24V with up to 1.5A from an external power supply. In practice it should also tolerate higher voltages and currents, but you probably want to check the schematic and datasheets to push the limits. Further it has a manual override switch in case of software issues or a failure of the raspberry pi. Simplified schematic:
Full schematic:
The hardware is designed to fit nicely into a HighPi Case, which has all necessary cutouts and can be mounted on a wall.
/opt/heatingControl/controlheating
mount / -o remount,rw
), but this is mainly recommanded for testing and maybe the initial configuration. Every change can be integrated into br-external
. This way the image can be build in a repeatable way./media/persistent/
. The mount options rw,sync,data=journal,barrier=1,noatime,commit=1
were choosen to avoid data corruption and wear of the sd card. It is only used to store store the current state at /media/persistent/last_state
and to restore it after a power loss. On every boot /etc/init.d/S10restorestate
tries to restore the last state. asterisk -rvvvv
. You can enable SIP debug mode with sip set debug on
.br-external/board/raspberrypi2-heating-control/rootfs-overlay/
. /etc/asterisk
. The build process automatically deploys the default configuration files. The overlay is used to overwrite them.
/etc/asterisk/sip.conf
/etc/asterisk/extensions.conf
CONFIG_IFUPDOWN_UDHCPC_CMD_OPTIONS=-R -b -O search"
. The option -b
sets udhcpc to run in the background. (-R
is release on exit, -O search
enables domain search option RFC 3397)rx
(in case we want to transfer a file via serial) ifplugd
(see above)/etc/asterisk/cdr.conf
). Busybox rotates syslog for us (CONFIG_FEATURE_ROTATE_LOGFILE)/etc/init.d/S15watchdog
starts the watchdog at boot and periodically writes to /dev/watchdog
.├──.github/workflows
├──audio-gen
├──hardware
└──software
├──buildroot
└──br-external
├── board
│ └── raspberrypi2-heating-control
│ ├── genimage-raspberrypi2-heating-control.cfg
│ ├── post-build.sh
│ ├── post-image.sh
│ └── rootfs-overlay
│ └── <config files and scripts>
├── Config.in
├── configs
│ └── raspberrypi2-heating-control_defconfig
├── external.desc
└── external.mk
.github/workflows
automatic build filesaudio-gen
infos about the audio file generation for the interactive voice menuhardware
pcb files for the 12V hatbuildroot
git submodule of buildrootbr-external
external overlay module for buildroot with all configuration and software files to build our custom linuxAfter making changes to the image, I like to test and verify that nothing broke by accident. The following test cases prooved to be useful. For now testing is done manually, but it would be an interesting idea to automate them.
The previous checks are usually enough, but here are some more:
ifconfig
if ip address is gone (takes a few seconds)ifconfig
if we get a dhcp leasepgrep -x asterisk
/var/log/messages
), watchdog only checks asterisk once every 60 secondswhile true; do logger hello; done
for some moments/var/log/messages
is rotated to /var/log/messages.0
and if file size is small (like 200kB)mdev
together with the devtmpfs
. On the other hand it won't enhance the security a lot, since asterisk is the only service on this device.