Amazon Dash Controlled Motion Sensing Camera (Part 1)

Recently a suspicious person showed up at my apartment. He was ringing every door to check which apartment was empty. He proceeded to pretend to be selling newspaper subscriptions when I answered the door, but he was clearly not: no uniform, no pamphlets or forms, no badge, wrong body language and wrong manner of speech. I filed a police report and they increased patrol in my area, but they can't possibly be expected to be around all the time especially when no actual crime occurred yet.

But we can do better can't we? I have a Raspberry Pi already configured and plugged to the network, so the solution is obviously to turn it into a motion sensing camera with motion. The cheap camera module I ordered is going to take a while to arrive however, so in the meantime I can only work the other parts of my setup.

Hardware

  • Raspberry Pi 3
  • RPi camera module
  • Amazon Dash button
  • A remote file server

The plan

Motion will be running as a service, recording whenever it detects any movement. Obviously, in the event there is a burglary there is the chance the RPi gets stolen or destroyed, so saving the recordings on a remote server is the obvious choice. As I previously managed to connect my RPi to my domain using SSSD, I plan on using the autofs service to automount the destination folder on my file server from the RPi. For some reason SSSD isn't starting the autofs service nor writing logs, so that part will likely come later. Using some cloud service could be an acceptable alternative too.

Obviously I don't want motion to record while I'm home. I originally planned on writing a quick phone or web app for controlling the camera. Or make a Bluetooth remote controller since the RPi3 has BT. But there was a cheaper solution: the Amazon Dash button. I personally like that solution since the Dash has a nice form factor and is inexpensive.

Setup

The Dash needs to connect to a wireless network, and relies on the Amazon app to receive the initial configuration. The annoying part is that 1) the Dash can't connect to 5 GHz networks, 2) it can't use WPA2-Enterprise (ok, I don't know any consumer IoT device that can, which is bullshit unfortunate) and 3) the Amazon app doesn't support Windows 10 (they do have a UWP app that is a complete joke). Annoying, but at $5 a Dash, something I can close my eyes on. Once the Dash is connected to Wi-Fi, abort the initial setup to prevent it from performing its intended purpose of ordering something on Amazon (lol). Now, get its MAC address either by looking for its ARP probe packet or simply by looking it up on your router, whichever is fastest.

Next, I used node-dash-button to make a quick app to listen to button presses. My implementation can also be found on GitHub

$> apt get libpcap-dev
$> npm install node-dash-button
$> nano app.js
const dash_button = require('node-dash-button');
const dash = dash_button('11:22:33:44:55:66', null, null, 'all');
const exec = require('child_process').exec;

const statusCmd = 'systemctl is-active motion.service';
const motionOn = 'systemctl start motion';
const motionOff = 'systemctl stop motion';
const ledOn = 'echo 1 | sudo tee /sys/class/leds/led0/brightness';
const ledOff = 'echo 0 | sudo tee /sys/class/leds/led0/brightness';

dash.on('detected', function () {
        console.log('Dash button pressed, checking service status');
        exec(statusCmd, function(err, stdout, stderr) {
                if(stdout === 'active\n') {
                        console.log('Service is active, turning off');
                        exec(motionOff);
                        console.log('Turning off LED');
                        exec(ledOff);
                }
                else {
                        console.log('Service is inactive, turning on');
                        exec(motionOn);
                        console.log('Turning on LED');
                        exec(ledOn);
                }
        });
});

Since my camera module is still not here, I can't verify the motion part works yet. Also, since it is currently not possible to control the LED lights on the Dash button, I have resorted to using the activity LED on the RPi for now. At some point I might add some other visual feedback since the activity LED is rather small and difficult to notice with the always-on red power LED. Apparently that power LED can't be turned off. I wanted to have it turn on and off automatically with sunrise and sunset but I digress.

Next, we want to run the node.js app as a service.

$> nano /etc/systemd/system/dash-monitor.service
[Unit]
Description=Amazon Dash button monitor
After=network.target

[Service]
WorkingDirectory = /path/to/node/app
ExecStart=/usr/bin/npm start
Restart=always
RestartSec=30

SyslogIdentifier=dash-motion

[Install]
WantedBy=multi-user.target

And install the service

$> systemctl start dash-monitor.service
$> systemctl enable dash-monitor.service