Door monitor: Difference between revisions
No edit summary |
|||
Line 10: | Line 10: | ||
The actual data passed comes in the form of a URL requested from the server. In the address, variables are passed to a php script using http get. The php script opens the log and updates it with the latest event. This server is run on my Raspberry pi since I already have another web server to host this website. | The actual data passed comes in the form of a URL requested from the server. In the address, variables are passed to a php script using http get. The php script opens the log and updates it with the latest event. This server is run on my Raspberry pi since I already have another web server to host this website. | ||
The end result is a log of when and which each door is opened or closed. The log looks like this: | |||
<pre>Sat, Jun 15, 2019 at 03:23:47pm - Sliding door opened | |||
Sat, Jun 15, 2019 at 03:23:53pm - Sliding door closed | |||
Sat, Jun 15, 2019 at 03:24:01pm - Sliding door opened | |||
Sat, Jun 15, 2019 at 03:24:07pm - Sliding door closed | |||
Sat, Jun 15, 2019 at 03:25:09pm - Inside door opened | |||
Sat, Jun 15, 2019 at 03:25:12pm - Inside door closed | |||
Sat, Jun 15, 2019 at 03:25:46pm - Sliding door opened | |||
Sat, Jun 15, 2019 at 03:25:50pm - Sliding door closed | |||
Sat, Jun 15, 2019 at 03:26:28pm - Inside door opened | |||
Sat, Jun 15, 2019 at 03:26:33pm - Inside door closed | |||
Sat, Jun 15, 2019 at 03:29:22pm - Ext. motion sensor tripped | |||
Sat, Jun 15, 2019 at 03:29:24pm - Ext. motion sensor closed | |||
Sat, Jun 15, 2019 at 03:29:26pm - Ext. motion sensor tripped | |||
Sat, Jun 15, 2019 at 03:29:28pm - Ext. motion sensor closed</pre> | |||
There are actually two logs, one in the above format and one that stores just a unix timestamp and raw data sent by the esp8266-arduino setup in the old alarm box. |
Revision as of 07:50, 17 June 2019
This one is an older project (2014), going back to one of the first ESP8266 boards I got my hands on. Perhaps your house is like mine, fitted with an alarm system that checks windows, doors, and motion sensors to detect break-ins or other unwanted visitors. It was here when we moved in, and I don't think was even supported by the original company anymore, not that we even had the intention of paying for a security subscription in the first place.
For all the bells and whistles the original system might offer, at the end of the day the sensors that actually run the system are made up of a bunch of switches that will either open or close when an event is detected. For example, magnetic switches on doors and windows will open when they are open, and motion detectors will either open or close for a few seconds whenever someone walks by. Conveniently, all the wires for these switches connect to the same point, which is the box that contains the original alarm controller.
Collecting the data
The first step was to remove the old controller board (as we weren't using it anymore), which leaves us with a bunch of wires. Many of these wires are switches, and the terminals can be found with a continuity tester. If a bundle has 4 wires, it's either two switches, or something that requires power, like a motion detector (or just one switch and nothing connected to the other two). The motion detectors we have use 12V DC, with the switch terminals isolated. Once power is applied, the other 2 terminals will be a switch that opens whenever the motion detectors switch. All said and done, I had about 8 or so switches that were connected to doors and motion detectors all over the house.
In these days, Arduino IDE for esp8266 did not exist, but NodeMcu Lua did. Of course, there was still the original firmware with AT commands. No matter what, the ESP01 modules I had only have serial communication, and two GPIO pins. The other system I had was an atmega328, which has only 2k of ram, so not the best for managing long strings, but, it does have about 19 pins to which I could attach all the switches. To interface the two microcontrollers together, I decided a straightforward approach would be to do monitor the switches on the atmega, and then send any changes to the esp8266, which would run Lua script to send that data to a server.
The actual data passed comes in the form of a URL requested from the server. In the address, variables are passed to a php script using http get. The php script opens the log and updates it with the latest event. This server is run on my Raspberry pi since I already have another web server to host this website.
The end result is a log of when and which each door is opened or closed. The log looks like this:
Sat, Jun 15, 2019 at 03:23:47pm - Sliding door opened Sat, Jun 15, 2019 at 03:23:53pm - Sliding door closed Sat, Jun 15, 2019 at 03:24:01pm - Sliding door opened Sat, Jun 15, 2019 at 03:24:07pm - Sliding door closed Sat, Jun 15, 2019 at 03:25:09pm - Inside door opened Sat, Jun 15, 2019 at 03:25:12pm - Inside door closed Sat, Jun 15, 2019 at 03:25:46pm - Sliding door opened Sat, Jun 15, 2019 at 03:25:50pm - Sliding door closed Sat, Jun 15, 2019 at 03:26:28pm - Inside door opened Sat, Jun 15, 2019 at 03:26:33pm - Inside door closed Sat, Jun 15, 2019 at 03:29:22pm - Ext. motion sensor tripped Sat, Jun 15, 2019 at 03:29:24pm - Ext. motion sensor closed Sat, Jun 15, 2019 at 03:29:26pm - Ext. motion sensor tripped Sat, Jun 15, 2019 at 03:29:28pm - Ext. motion sensor closed
There are actually two logs, one in the above format and one that stores just a unix timestamp and raw data sent by the esp8266-arduino setup in the old alarm box.