I did this in stages and added a piece at a time.
I combined several tutorials to achieve the desired effect.
First was the display cameras script.
Next was WeMo emulation.
Next was CEC command functionality.
Finally I combined the WeMo and CEC commands.
As an interim step after I got the WeMo emulation running, I used a GPIO script to drive a relay.
That way you could issue voice commands to do something like close the garage door.
What I learned from that allowed me to substitue the GPIO script for the CEC commands.
I don't think I'll post that here because I don;t wantt o cause confusion.
I'll post the commands I used with the RPi for each section. You should be able to cut and paste these in an SSH session using PuTTY or another client.
First the Display Cameras Script.
I used this tutorial:
https://community.spiceworks.com/how_to/123787-raspberry-pi-powered-surveillance-camera-monitoring-display
Start with a clean install of the latest Raspbian Jessie.
Then make sure everything is up to date
Software
Code:
sudo apt-get update && sudo apt-get upgrade -y
Firmware
Code:
sudo apt-get install rpi-update && echo Y | sudo rpi-update
Display cameras uses Omxplayer & Screen
Install Omxplayer & Screen
Code:
sudo apt-get install omxplayer
sudo apt-get install screen
Then increase the GPU memory
Use raspi-config
Set aside 256-512 MB to GPU
Also, while in raspi-config, tell the script to hold until network is available.
Select "Wait for Network at Boot" in raspi-config.
Determine the camera layout math and pixel coordinates, see link above for several examples.
Edit config.txt to set memory and display limits
You want to set the output up for display on a TV.
Code:
sudo nano /boot/config.txt
Add or un comment lines
For 16:9 display
sdtv_aspect=3
Group=1=CEA, mode=16=1080P 60Hz
hdmi_group=1
hdmi_mode=16
Determine your camera stream URLs. I tried this with both http and RTSP streams and it works with both.
I'm using Vivotek cameras, use the URL for your particular camera.
I also set up a view only user ID and password on the cameras so I wasn't using the root password.
The script will auto scale the streams, but I found that after it ran for awhile the screen went blank. Even with the screen saver turned off. Since I have 4 streams per camera, I ded icated one to this task and formatted it as a 640x480 native resolution and used that size for each display panel.
Create "displaycameras" script
Replace the <...camX url...> with the RTSP or RTMP or http URLs for your cameras.
NOTE: The command that calls the first camera feed (line 13) has the added option, "-b", which sets background to black
Code:
sudo nano /etc/init.d/displaycameras
Script contents for 4x4 layout 4:3 with 640x480 sources (or windows) 21 pixel frame above and horizontally between feeds:
--------------------------------------------------------------
#!/bin/bash
### BEGIN INIT INFO
# Provides: omxplayer
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Displays camera feeds for monitoring
# Description:
### END INIT INFO
# Camera Feeds & Positions
top_left="screen -dmS top_left sh -c 'omxplayer --win \"0 21 640 501\" rtsp:// <...cam1_url...> -b --live '";
top_right="screen -dmS top_right sh -c 'omxplayer --win \"640 21 1280 501\" rtsp:// <...cam2_url...> --live'";
bottom_left="screen -dmS bottom_left sh -c 'omxplayer --win \"0 522 640 1002\" rtsp:// <...cam3_url...> --live'";
bottom_right="screen -dmS bottom_right sh -c 'omxplayer --win \"640 522 1280 1002\" rtsp:// <...cam4_url...> --live'";
# Camera Feed Names
# (variable names from above, separated by a space)
camera_feeds=(top_left top_right bottom_left bottom_right)
# Sleep for 1 minute on startup to allow network to establish
# This line is optional, but helps with the periodic restarts we'll initiate in crontab
# It will delay startup for one minute when you run the application.
# This may cause you to think it's not working correctly.
# I recommend commenting the line below out during testing.
sleep 1m
#---- There should be no need to edit anything below this line ----
# Start displaying camera feeds
case "$1" in
start)
for i in "${camera_feeds[@]}"
do
eval eval '$'$i
done
echo "Camera Display Started"
;;
# Stop displaying camera feeds
stop)
sudo killall omxplayer.bin
echo "Camera Display Ended"
;;
# Restart any camera feeds that have died
repair)
for i in "${camera_feeds[@]}"
do
if !(screen -list | grep -q $i)
then
eval eval '$'$i
echo "$i is now running"
fi
done
;;
*)
echo "Usage: /etc/init.d/displaycameras {start|stop|repair}"
exit 1
;;
esac
--------------------------------------------------------------
Next, change permissions for displaycameras script to make it executable
Code:
sudo chmod 755 /etc/init.d/displaycameras
Script Use:
Start the camera feeds:
Code:
/etc/init.d/displaycameras start
Close the camera feeds:
Code:
/etc/init.d/displaycameras stop
Re-open any closed camera feeds:
Code:
/etc/init.d/displaycameras repair
Update the rc.d file to initialize the script on startup
Code:
sudo update-rc.d displaycameras defaults
sudo update-rc.d displaycameras remove
I recommend setting a static IP address.
This will come into play later with the WeMo emulation.
Set up automated reboot and restart using the crontab
crontab options * * * * * (five registers * = all of that category)
registers 1-5
1) min (0-59)
2) hour (0-23)
3) day of month (1-31)
4) month (1-12)
5) day of week (0-7) : 0 and 7 are both Sunday
0 3 * * * sudo reboot -> reboots the PI everyday at 3AM -> 3:00
1-59/5 * * * * /etc/init.d/displaycameras repair -> restarts the cameras every 5 minutes if they hang but not during reboots -> i.e. minute 0 to 1 not included
Edit the crontab
Add to bottom of file:
--------------------------------------------------------------
0 3 * * * sudo reboot
30 0-23/4 * * * /etc/init.d/displaycameras repair
--------------------------------------------------------------
Turn Off screen saver
Code:
sudo nano /etc/kbd/config
BLANK_TIME=0
POWERDOWN_TIME=0
setterm -blank 0 -powerdown 0
That's it for the first part.
Here are two links I used for the next part.
Alexa WEMO
http://www.instructables.com/id/Hacking-the-Amazon-Echo/
GPIO Relay
http://www.instructables.com/id/Control-Any-Remote-From-a-Raspberry-Pi-and-Amazon-/?ALLSTEPS