This project/article is under construction. Neither the instructions nor the finished product are guaranteed to work at all.
I’ve always wanted a fancy alarm system, but several factors prohibited it. First, I hate monthly payments of any kind and seek to eliminate them in my life as opposed to invite more of them. Second, I don’t like other people having access to sensors or cameras (or the data from them) in my house. Third, I don’t like things I can’t alter to suit my will, and no commercial alarm system I’d come across seemed reasonable to my needs.
So I built one.
The RPiPRS is built around an original Raspberry Pi A with cheap 433mhz superheterodyne RF chips connected to the GPIO. NinjaBlocks keeps some slick RF code on their github, which I use as the RF listener. I’ve modified their C code to pass signals to a set of shell scripts which perform one or more actions based on the alert, alarm state (armed, monitor, etc). In the simplest example, the words “front door” are played from attached speakers when the front door is opened. In the most complex, the system monitors when my cats are in the area. It can send emails when I’m away (no SMS yet unless your carrier has a smtp->sms gateway) and can play an alarm noise automatically or on-demand.
The only current limitation is that it’s under heavy development so has funny bugs now and then, and that a lot of it is solely 433mhz RF based, so relatively easy to overload. All that said, here’s how it’s built.
1. Set up the Pi
1. Prep a fresh Raspbian SD card
# dd if=2016-03-18-raspbian-jessie-lite.img of=<your SD card>
2. Update and reboot the Pi
# sudo apt-get update
# sudo apt-get upgrade
# sudo init 6
2. Finish and localize the installation
# sudo raspi-config
- Choose Expand Filesystem, confirm, reboot, and re-enter raspi-config.
- Choose Internationalization, Change Locale, unselect en_GB*, and select en_US.UTF-8
- Choose en_US.UTF-8 as the default locale for the system environment
- Choose Internationalization, Change Timezone, and set the correct time zone
- Choose Internationalization, Change Keyboard Layout, and reset to US keyboard (optional)
- Choose Internationalization, Change Wifi Region, and set the correct region (optional)
- Choose Advanced Options, Change Hostname, and rename to something slick like pisec (optional)
# sudo init 6
3. Install some needed software
The Pico TTS packages produce wav files that can be easily played by aplay. One of the necessities of this system is full functionality during an Internet outage, so locally-played files is better than using on-demand audio from the internet.
# sudo apt-get install libttspico-utils
WiringPi is needed to interface the RF hardware, and git is needed for WiringPi.
# sudo apt-get install git-core
# git clone git://git.drogon.net/wiringPi
# cd wiringPi
SSMTP or Exim4
The system also needs to send email. SSMTP is easiest, but it has an unpatched security hole in Debian at the time of this writing. Exim4 will have to do despite taking longer to set up and using more resources. SSMTP setup instructions are also included for when the hole is patched.
Exim4 (either use this or SSMPT)
# sudo apt-get install exim4
# sudo dpkg-reconfigure exim4-config
For setup options, select:
- mail sent by smarthost; received via SMTP or fetchmail
- system mail name should be the same as the hostname (pisec)
- Leave the IP address as-is (127.0.0.01 ; ::1)
- Other destinations for which mail is accepted: raspberrypi
- Leave relay blank
- Outgoing smarthost: smtp.gmail.com::587
- Hide local mail name: No
- Keep DNS queries minimal: No
- Delivery method: Maildir format in home directory
- Split config files: No
- Root address: leave blank
Add the Gmail account credentials to a password file and restart Exim.
# sudo nano /etc/exim4/passwd.client
Add the following lines, replacing YOU with your username.
gmail-smtp.l.google.com:YOU@gmail.com:PASSWORD *.google.com:YOU@gmail.com:PASSWORD smtp.gmail.com:YOU@gmail.com:PASSWORD
# sudo update-exim4.conf
# sudo /etc/init.d/exim4 restart
SSMTP (either use this or Exim4)
SSMPT is much simpler than Exim4, but may not work on all distributions. Or at all.
sudo apt-get install ssmtp
sudo apt-get install mailutils
Once installed, edit the SSMTP configuration file.
sudo nano /etc/ssmtp/ssmtp.conf
Add the following and save the file, replacing YOU once again.
This part is from NinjaBlocks, and is fundamental to the RPiPRS.
# git clone –recursive git://github.com/ninjablocks/433Utils.git
# cd 433Kit/RPi_utils
4. Set up RPiPRS scripts
Create a directory called “sec” for user pi
# mkdir /home/pi/sec
# cd /home/pi/sec
# wget <download coming soon>
# gzip -d latest.tar.gz
# tar xvf latest.tar
5. Get one or more WAV file sets
Pico needs to generate wav files for playback. A set of standard audio is included in the default file, but can be edited as needed. Once the quotes are satisfactory, the get_audio.sh script will quickly create the audio clips and save them to the local SD card.
# cd /home/pi/sec/audio/pico
# nano quotes
6. Set up cron job to monitor for RFScanner (super basic daemon)
# sudo crontab -e
Add the following to the file to check every minute. This only ensures that RFSniffer is running, and not in an elegant way, but it works for now.
* * * * * /home/pi/sec/scripts/daemon.sh
7. Create a little space in RAM for temp files (to extend the life of the SD card)
This step is undergoing review at the moment and isn’t working well.
# sudo nano /etc/fstab
Add the lines:
tmpfs /tmp tmpfs defaults,noatime,size=5m 0 0
tmpfs /var/log tmpfs defaults,noatime,size=64m 0 0
The script will keep its status in /tmp and the Linux system will write logs to the 64M memory chunk, preventing the SD card from being read/written more than necessary.
8. Start it up
The cronjob from step 6 should have started RFSniffer by now, but no devices are configured so no alerts will be triggered. The next step is to set up some hardware, both on the Pi and around the house!
2. Set up the Sensors