fvollmer / SIP-Heating-Gateway

Remote control any device by calling your raspberry pi with your phone via sip
Other
2 stars 0 forks source link
asterisk asterisk-pbx buildroot embedded embedded-linux phone raspberry-pi remote-control sip voice-menu

SIP Heating Gateway

build

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.

Usage

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. Enter the PIN and press #
  2. Press 1 to turn the heating on, 2 to turn the heating off, 3 to get the status of the heating
  3. Repeat step 2, or hang up

After 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

Configuration

The custom embedded system is based on buildroot. The behaviour at a call is controlled by Asterisk. There are two main configuration files:

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:

How to build the sd card image

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:

  1. Clone repository (use --recursive to get buildroot submodule)
  2. Change into software folder (cd software)
  3. make BR2_EXTERNAL=$PWD/br-external -C buildroot raspberrypi23-heating-control_defconfig
  4. make -C buildroot
  5. write buildroot/output/images/sdcard.img to sd card (e.g. dd if=buildroot/output/images/sdcard.img of=/dev/mmcblk0 bs=1M && sync)

Hardware

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.

Good to know

Overview of files

├──.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

Test cases

After 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:

Enhancement Ideas