This is the application package for my alarm system interface. It consist of a firmware, host application, and various (mostly shell script) tools. I made nai (short for nalarminterface) to be able to interact with my alarm box in my house, send an email if there was an alarm, turn on/off the motion detecion in the IP cameras if the alarm is armed or disarmed etc.
As I have a Zyxel NSA325 NAS with FFP running 24/7, the alarm interface and the TC35 GSM module are connected to it via USB. See this guide for installing FFP on this NAS.
The shell scripts need my logrotate script which can be found in a separate git repo here.
The alarm system has two wire outputs which have +13.5V on them if there's an alarm or if the system is armed. I also have an EP98 sound detection sensor which outputs 5V and 0V when a loud enough sound is detected. These 3 wires are connected to an atxmega128a3u development board through optocouplers:
There are 4 of these optocoupler units on the AVR board:
Here's the input connection schematic of the board:
Note that P4's optocoupler is not used, a sound detector is connected to the MCU instead. Here's the sound detector's interface:
I think the code is well commented and easily readable, so it can be a nice example for using USB on the xmega with libusb on the host. EEPROM reading/writing, interrupt driven UART console, RTC (for tracking elapsed time and blinking the LED), ADC (for reading the uC VCC) and - of course - GPIO pin interrupt watch are used as well.
This is the firmware for the AVR board. The board can be programmed with an AVR ISP programmer. Maybe the on-board factory USB bootloader can be used for programming as well, but I think the AVR Flip software is a crap on Linux. It watches 4 input pins and notifies the host application through USB if there was an interrupt. It has an UART serial console (can be used with a 3.3V UART-USB converter like these). Various debug commands can be used on the console (for the full list enter "help", or see console.c). If an interrupt happened, the status will be saved to the EEPROM, so if there's a power outage, the alarm will be delivered as soon as power comes back and the hostapp connects to the interface again. If there was an error with saving to the EEPROM (like the EEPROM location is faulty), the EEPROM location will be incremented by one, and the hostapp gets notified about this failure.
The sources in this directory are used both by the avrboard and the hostapp.
These scripts can be used to control Foscam 9820W V2 IP cameras. The documentaion of the used API can be found here.
This is the host application which connects to the avrboard interface through USB, periodically checks the connection and waits for an interrupt. It starts a shell script when an interrupt happens or the EEPROM counter increases. These shell scripts can send emails or do other things.
The hostapp application is meant to run on my Zyxel NSA-325 NAS with FFP, it can be easily compiled both to ARM and x86.
The script here can be used as a wrapper for msmtp to easily send emails.
I'm using a Siemens TC35 GSM module for sending an SMS when there's an alarm. The module needs it's IGN pin to be pulled down to GND for at least 100ms and then released to start working after powering on, so I had to build a little circuit with an ATtiny25 MCU which does that. The source code for the "igniter" MCU is in the tc35/igniter folder. Here's the schematics for the igniter board:
Handling SMS is done with gammu-smsd. There's an example config file for it, and for the native gammu as well.