Introduction: Internet Enable a HKC Home Alarm
I have published a couple of Instructables for different alarm panels - this one is to enable you to remote control the HKC Secure Watch alarm panel.
The finished item looks very like an Aritech Remote Access project I have documented here also - but the electronics and code for this project was considerably more difficult to create and so warrants a separate instructable.
This panel was installed from around 2000 to 2010. They are a very common sight in the Homes in many countries all around Europe. I am not sure of how common they are outside Europe.
Sometimes they will have been re-badged with custom stickers by the installers, but they all have an easily recognizable keypad. They are a good system with many interesting features - but they lack the ability for the home owner to connect to it over the Internet.
This project is about reverse engineering the alarm panel to add this missing functionality. It will add the following:
* Ability to contact the panel via a mobile device and set/unset/view logs from anywhere
* Have the Alarm system email you if the Alarm has gone off
* Allow you to enter engineering menus and configure the alarm panel remotely.
Total cost of all parts will be much less than $20
Even if you do not own this Alarm - you may find some of the code useful for remote operation of other devices you might own - As well as the Keypad emulator, the Arduino code features a HTML webserver, HTML pages, Email client, Websocket Webserver, DES encryption and Base64 libraries.
Notes: All photos and screenshots are original by myself (as per Instructables guidelines) - the code and circuit design were created by me.
Step 1: The Plan
The plan was to get an Arduino to Emulate the alarm panels' Keypad.
The HKC panel would think it was a standard keypad - but it would in fact be talking to an Arduino - this Arduino has no keypad or display - it instead has a webserver with which you can connect to over the internet.
The server delivers a website which uses websockets as the communication transport to give a very responsive emulated keyboard in html. Several key presses are buffered to give a response that rivals the original keypad.
The Arduino is installed at any point on the HKC Bus - I placed mine inside the Alarm Panel cabinet - but you could attach to the Keypad end if your Ethernet connection is closer to there.
Also it is possible to use an Ethernet to Wifi adapter if the Alarm Panel is a distance from any Ethernet connection - a wired Ethernet cable though is preferable though for ease of installation and reliability of the system.
Step 2: The Parts
The required parts list is:
- Arduino Uno R3 (amazon link £6)
- ie. a standard arduino - clones can be bought from $5 upwards
- Arduino Ethernet shield (amazon link £7)
- Another standard Arduino part - Amazon sell them for aprox $10 upwards
- DC-DC power supply (link or link) about $4
Used to convert the Panels 12Volts to a stable 5Volts
- Three Transistors BC109 (or any similar general purpose NPN transistors such as 2N2222 or 2N2369)
- Resistors as specified in the schematic
- Mini breadboard
You will also need the Engineer (Admin) Password for your HKC Alarm.
If you don't have the password, you may consider defaulting the panel to factory defaults and reconfigure it - see the manuals for this procedure. There are other methods for removing the password but they are outside the scope of this instructable.
Powering the Arduino
The DC-DC power supply is the most critical component to get correct - don't be tempted to use cheap car 12V to 5V Adapters - the voltage of the cheaper adapters I tested contain a ripple voltage that can cause the Arduino to crash randomly.
I don't recommend using the Arduinos built in 9V socket when using the Ethernet adapter or using the Alarm Panels 5V power - things will get hot! The DC-DC adapter specified above is very efficient and provides a very stable 5V without heating up - I apply this 5V to the 5V pin of the Arduino.
If you decide to power from a mains powered usb adapter (eg. phone adapter) and not the module recommended above - you will need make sure this adapters output GND is connected to any of the panels ground; as everything needs to share the same GND.
I used a small mini-breadboard to prototype the system. If you make it neat enough - the breadboard is good enough to use as a solution for many years - but you may like to make up a soldered version using, for example, the small prototype shield shown in the last photo.
Step 3: The Build
It is required to build a custom circuit to interface the Arduino 5V pins to the 12V bus of the HKC.
Although the HKC has 4 wires connecting the keypads - only 3 are actually used. Two wires are Ground, One is +12v and last is a Data line which is used for both receiving and transmitting to and from the alarm panel.
So we need a circuit that will split this up into two separate RX and TX for Arduino as well as perform the voltage conversion between 5V and 12V. The signal is also inverted to how the Arduino likes it. The circuit must also be capable of disconnecting from the bus when its not its turn to talk - so as to not interfere with the operation of the other keypads on the bus. I tried where possible to use the same parts to make purchasing easier - so for example the three transistors are all identical.
It took me some time to make it with as few as components as I'm showing here.
It requires three transistors but is not terrible difficult to assemble. The actual transistors are used can be selected from the compatible ones listed in the last step - the resistors values must be as specified. If using metal capped transistors be sure that the metal caps don't touch off anything as they are frequently connected to one of the transistors pins. No heatsinks are required as the circuit is designed to use minimal current.
A photo is shown of the breadboard .
Any questions about this - ask and I can try help - I've tested this the two different models of HKC panels I own here - it may work with other models. For other brands of alarm you may want consider my other generic remote control alarm instructables.
Step 4: Arduino Code
The code is complex - it was a major effort, and several tricks needed to be employed to squeeze all this code (keypad emulator, HTML webserver, HTML pages, Email client, Websocket Webserver and DES encryption and Base64 libraries) all into the tiny Arduino UNO 32K flash and ram space.
All the code is hosted here:
I will update the project code every while - so be sure to Fork the project so you get notifications when there is an update.
Just download all the files (important: use the download zip button rather than one file at a time).
Place them in the same folder - and open the .ino file in Arduino IDE.
There is a config file in the project config.h - this is where you set your IP address, your email address and other options. It is well commented with all the options to choose from.
Compile and Upload to to Arduino. You will need disconnect the Arduino completely from the Alarm panel to program it- as if anything connected to the Arduino RX & TX (pin 0 &1) it can interfere with the programming progress.
Also its best not to have the 5V power supply connected to the Arduino And the USB connected to a PC at the same time.
Developers - Customizing the software
There is a software serial out for debugging - you can connect this via a TTL to USB to view logs from the arduino. The flag to enable debug mode is off in the code provided by default. I found Visual Micro to be a much better development environment than the Arduino IDE.
An oscilloscope & digital signal analyser were vital to decoding the protocols used.
For the Curious - How I reverse engineered the protocol
- I connected two keypads
- I measured the baud rate using an oscilloscope. I could see it was a surprising 9bit and unusual baud rate which was challenging to get working on the Arduino (as the Arduino Libraries don't support only 8bit). The extra bit was used to signal the start of a new message.
- and using suitable voltage leveling resistors had an Arduino listen in on the traffic on the one wire data bus and send to the pc.
- Each keypad I placed a different resistor on the data line, so I could identify when the alarm, keypad1 or keypad2 was using the line by monitoring the voltage level as well as read the message.
- By operating each function, I could see the relevant message packets the keypads and alarm sent; I could see a command byte for the various functions; display text, light led, sound buzzer etc. and the display text sent as plain text, each with a checksum byte.
- and I duplicated this functionality in the code.
The code to register a new keypad was the most difficult.
Step 5: Connection and Final Notes
To install this project - you need to tell the HKC Alarm panel there is a new keypad on the bus - Enter Engineering mode and select the option from the menus to "Install Remote KeyPad".
If you have wired everything up ok you should see a new keypad being registered on the display.
Accept this and exit Engineering menu.
There are no keypad IDs to set - the ids of the keypads are all determined when you do the bus scan - however the Arduino will try its best to position itself as keypad 2.
To uninstall at any time is easy- just enter Engineering menu, remove the Arduino and run the "Install Remote Keypad" procedure again.
If the Alarm Panel sees a keypad not responding it will sound the alarm - so if you you want to remove the Arduino at any stage, to work on it etc. - just enter the Engineer menus while you do so - the Alarm will Not sound when you are in Engineering Menu - your neighbours will appreciate this tip also.
To Connect to panel. Browse to the IP address: Check the config for the address setting - in this version of the software I've defaulted it to "http://192.168.1.205:8383".
It works with most modern browsers and mobile phones.
You can make this accessible from outside the home by port forwarding on your home router and optionally using one of the free Dynamic DNS services. Just consider increasing the security below.
Especially if you are opening up access externally to the house- consider these tips to increase the difficulty of anyone guessing your password.
Change the Port to some random number (default is 8383)
Consider having an Alarm Panel password 6 digits long (default is 4 digits long)
Make sure the User and Engineer(Admin) Password on the HKC Alarm Panel are not the default passwords.
At a minimum you should enable "Panel Tamper" on the alarm panel that will lock you out for a minute after 10 or so bad guesses to prevent brute force guessing of the password.
Future Work and Known issues
To determine if the Alarm has gone off - the Arduino looks for the message to the keypad to Light the RED warning light Led on the Keypad - this is the only way the keypad will know the alarm has gone off - unfortunately it has since been discovered that this led also flashes briefly when you part set the alarm. So you get an email sent to you when you part-set the alarm - doh - I will correct this when I get my environment set up again. Still works fine otherwise though.