Alarm Button

This is a simple project which is either a door-bell, or an alarm-button depending on your viewpoint!

In short it is a button connected to an ESP8266 device. When the button is pressed a message is posted to a queue. A watcher can consume this event and do anything you like! The sample watcher included in the repository, and what I use it for, merely triggers the playback of an mp3 file.

Hardware

Wiring the project is very simple, and merely consists of connecting the button to the Mini D1, which is powered by a simple USB-PSU. I wired the button between D0 & D8.

The final result looks something like this:

Software

The software for this project is very simple, and logically divided into two parts:

Handling connections to the local WiFi network.

This is required to send the message to the MQ bus.

Reacting to the button-press.

By publishing a "click" event.

I've also added support for over-the-air-updates, which means that new code can be flashed on the deployed harware without touching the cabling, directly from the Arduino IDE.

Operation

If you've previously configured WiFi details the device will connect automatically, and begin working. If you've never configured the device it will instead notice that, and configure itself as an access-point. This means you can use your mobile phone, or other WiFi-connected device, to connect to this access-point and select the local WiFi network it should become part of.

Once running the system will quietly wait for button presses, when one is received it will publish a message via the MQ-broker, which will look like this:

{"click":"short","mac":"a0:20:a6:16:45:d2"}

Or:

{"click":"short","mac":"a0:20:a6:16:45:d2"}

i.e. The payload will be a JSON object with a click field. This event will be pushed to the "alarm" queue.

If you have multiple buttons you'll be able to differentiate them via the mac" field.

The Code

The main code looks like this:

Several libraries are used, and these are bundled together in a git repository, you can access all the source by cloning the repo involved, and then looking at the project:

In the repository you'll also find a simpler queue-watcher, written in perl, that will trigger the alarm playback. This uses a script which is Linux-specific and assumes you're using the mpd audio-stuff.

Alternative Approaches

Building a single button like this was fine, but over time I wanted more.

Rather than building multiple alarm-buttons I decided it was better to make the buttons as dumb as possible, and put the "smarts" on my PC.

That lead to the use of simple radio-transmitters and a software-defined radio receiver: