First, I want thank @alexyak for his motioncontrol module. Unfortunately for me, it doesn’t work on my Mirror due to new security controls put in place by the Node.js team. Apparently it’s not a wise move to let client-side Javascript access the webcam attached to your server. Who knew?
In the end, I ended up seeking another solution. The Facial Recognition module didn’t work due to the reduction in light coming through the mirror itself. But I do get an image. I started browsing sites of people who have turned their Raspi into a security system. It turns out, someone ported the Motion framework to Raspberry Pi and called it MMAL-Motion.
After a lot of reading, I found a Wiki for MMAL Motion. Following the steps for Jessie, I did the following:
- Change to your home directory.
cd ~
- Install the library dependencies (just copy & paste into the terminal. I wouldn’t want to do this by hand)
sudo apt-get install -y libjpeg-dev libavformat56 libavformat-dev libavcodec56 libavcodec-dev libavutil54 libavutil-dev libc6-dev zlib1g-dev libmysqlclient18 libmysqlclient-dev libpq5 libpq-dev
- Download the precompiled binary archive file:
wget https://www.dropbox.com/s/6ruqgv1h65zufr6/motion-mmal-lowflyerUK-20151114.tar.gz
- Uncompress the archive file
tar -zxvf motion-mmal-lowflyerUK-20151114.tar.gz
This will put a configuration file called motion-mmalcam-both.conf and a folder called motion in your home folder. At this step you can test it if you like, but for my purposes I needed to make a few changes tot the config file. So, make a copy and edit the copy.
cp motion-mmalcam-both.conf motion.conf
nano motion.conf
I played around with the configuration quite a bit until I found one I liked. But for our purposes (turning the display on when someone comes near) you only have to make a few changes.
framerate 4 - run the detection video at 4 frames per second
threshold 2500 - increase the # of pixels to trigger the screen. We want them to get close to the mirror
minimum_motion_frames 2 - Motion must be detected in 2 consecutive frames (at 4 FPS)
event_gap 60 - This is important. This is how long in seconds after no motion the screen will turn off.
output_pictures off - Do not save images
ffmpeg_output_movies off - Do not record video
stream_port 0 - Turn off remote viewing
webcontrol_port 0 - Turn off HTTP control of camera
on_event_start vcgencmd display_power 1 - Important! This is the command to turn on the screen
on_event_end vcgencmd display_power 0 - Important! This is the command to turn off the screen
Save your motion.conf file and now you can test it out by entering ./motion -c motion.conf. If you stay very still for a minute, the screen should turn off. Move close to the mirror, and everything should come back after a couple seconds.