Security System Project

I just posted the code that I am using for my security system on GitHub.

As always, I highly appreciate comments on better code, methods, ect. My system communicates with an iOS app, which I will be publishing soon, though all communication back and forth is JSON, so you could easily create a web interface.

I created it with essentially get and set methods, so that the control interface can sync (get) its control settings from the agent/device when it loads, and then set the controls with user input. This allows the use of multiple control interfaces and keeps all of them on the same page. The agent and the device both have their own sets of state variables.

The next piece that I would like to look at is a better authentication of control devices. I’d like to hear ideas on that, if anyone has them.

My system has magnetic switch sensors connected to 5 pins and uses callbacks to detect an open circuit. A transistor-relay circuit drives the 12V siren. I am using an imp002 so that I’ll have plenty of pins to connect fire detectors and other sensors, and possibly a hardwired touchscreen control panel.

SMS alerts are handled by sending from the agent to Twilio.

Hello, I’m new to all this, but would really like to use this on my alarm system. I signed up for an account on Twilio so I have the information to put into the server, but I don’t know where to get this information “apiKey <- “” // Enter your API Key here” Can someone tell me what an apiKey is, or where I get it. Thanks Dave…

Twilio will provide you with an API key. Essentially it is a password that you send to the Twilio servers when you make an HTTP request. If you have an iPhone or iPad, take a look at Pitchfork for use with a security system project. I really need to update this project.

Thanks for the quick response. I see on Twilio where it says “Note: Toggle showing your Auth Token by clicking here” is that the number that goes in your program where it asks for the apiKey? Does the program you have posted on gethub still work with the electric imp? Sorry for all the questions, but this really has my interest.

It’s clever (thinking outside the box) to use an April board as your 3.3V regulated power supply. Is there a reason you use that instead of a 3.3V regulator (3-pin TO-220 package)?

I’m just curious, because maybe the April board is a nice regulator for only $13.

Sorry, I wasn’t thinking. The apikey is for interfacing with my Pitchfork app. You make up an API key… preferably a nice long one, but whatever you want.

@mlseim The SD card socket came off of that board so I just used it for the regulator.

Soon I’ll be dropping in my own design! :slight_smile: Hoping to launch themakedeck.com by next weekend!

cool project ! if I had a security system like this I would be up for doing this project. I had a look at the code and have a thought, though being such old code maybe I am late to this party.

in the device code, json is built up as a string. I have found it helpful to build tables in squirrel and transfer those between device and the agent. In the agent it is easy to build json strings. I think there is probably some efficiency of bandwidth. I have also been told squirrel has some difficulty working with strings although in my projects I use lots of strings and have never noticed a problem. anyway…

like this;

device
`
local smsArmed = “off”;
local sirenArmed = “on”;
local sensorState = “on”;
local sirenState = “off”;

local _table = {status =
{auth = “yes”,
smsArmed = “off”,
sirenArmed = “on”}};

server.log(_table) ;
agent.send(“statusResponse”, _table);
`

agent
`
device.on(“statusResponse”, function(data) {

    server.log(data);
    local _data = http.jsonencode(data);
    server.log(_data);

}); `

should return something like this

[Device] (table : 0x200104a0) [Agent] (table : 0x7fe298260df0) [Agent] { "status": { "smsArmed": "off", "auth": "yes", "sirenArmed": "on" } }

Thats a good point. The security system project needs an overhaul.