Introduction: Raspberry Pi Garage Door Opener With Streaming Video of Door Status.
This Instructable modifies two other guides. Just got a Magnetic Sensor hooked up with door status on page.
Step 1: Do This Instructables First
You need do this Instructable @ https://www.instructables.com/id/Raspberry-Pi-Gara...
In above external Instructable:
- Instead of step 1
- Download Rasbian Jessie Lite has no GUI
- Unzip the IMG
- Use Etcher or some SDCARD imaging software for the IMG
- Open the boot directory on the SDCARD and make a "ssh" file so SSH will work
- Place card back in Raspbarry Pi2 or 3
- Turn on
- Before step 3
- ssh to you pi
- sudo raspi-config
- #1 change the password from default
- #2 change hostname
- #3 Boot options
- B2 yes
- #4 Localisation .....
- I1 , I2, I3
- #5 Interface options
- P1 enable Pi camera
- #7 Advanced
- A1 expand file system
- #8 Update tool to latest version
- Finish
- Reboot
- Update Raspbian and its packages
- sudo apt-get update
- sudo apt-get upgrade
- sudo reboot
- Continue Step 3 above
Step 2: Get the Camera Working on Raspbian Jessie
Ok here is the proper way to get the camera working:
Install motion to get dependecies.
sudo apt-get install motion
sudo apt-get install libjpeg62
Create a directory in your home called mmal
cd ~/
mkdir mmal
cd mmal
Download @maya fork of dozencrow’s motion program that works with Rasbian Jessie
wget https://www.dropbox.com/s/6ruqgv1h65zufr6/motion-...
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
tar -zxvf motion-mmal-lowflyerUK-20151114.tar.gz
./motion -c motion-mmalcam-both.conf
It should work now when you goto RaspiIP:8081
CTRL-C to quit
Edit the config file and make changes
nano motion-mmalcam-both.conf
target_dir /home/pi/mmal/m-video
output_pictures off
framerate 100
Step 3: Edit /var/www/css/style.css Next
pi@raspberrypi$ nano /var/www/css/style.css
Replace all the text with this
html,body {
margin:0px;
padding:0px;
background:#263238;
background-size: 980px 735px;
background-repeat: no-repeat;
text-align:left;
}
div.awrap{
position:fixed;
height:150px;
left:110px;
top:792px;
width:760px;
text-align:left;
}
a {
display:inline-block;
border-radius: 15px;
border: 2px solid #263238;
width:760px;
height:150px;
background:#B5B1B1;
-moz-box-shadow: inset 0 0 10px #000000;
-webkit-box-shadow: inset 0 0 10px #000000;
box-shadow: inset 0 0 10px #000000;
-webkit-tap-highlight-color: rgba(255, 255, 255, 0);
}
a:active {
background:#263238;
-moz-box-shadow: inset 0 0 50px #000000;
-webkit-box-shadow: inset 0 0 50px #000000;
box-shadow: inset 0 0 50px #000000;
}Step 4: Modify Sudo Nano /var/www/index.php
Download index.txt and then rename to index.php and put in /var/www/
Step 5: Make Your Webpage More Secure
In order to create the file that will store the passwords needed to access our restricted content, we will use a utility called htpasswd. This is found in the apache2-utils package. This was installed in Step 1.
pi@GaragePi2:~ $ sudo htpasswd -c /etc/apache2/.htpasswd pi
(You will be asked to supply and confirm a password for the user)
New password:
Re-type new password:
Adding password for user pi
If we view the contents of the file, we can see the username and the encrypted password for each record:
pi@GaragePi2:~ $ cat /etc/apache2/.htpasswd
pi:$xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/
Configuring Access Control within the Virtual Host Definition
Begin by opening up the virtual host file that you wish to add a restriction to. For our example, we'll be using the 000-default.conf file that holds the default virtual host installed through Raspbian's apache package:
sudo nano /etc/apache2/sites-enabled/000-default.conf
Inside, with the comments stripped, the file should look similar to this:
ServerAdmin webmaster@localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Authentication is done on a per-directory basis. To set up authentication, you will need to target the directory you wish to restrict with a block. In our example, we'll restrict the entire document root, but you can modify this listing to only target a specific directory within the web space. Within this directory block, specify that we wish to set up Basic authentication. For the AuthName, choose a realm name that will be displayed to the user when prompting for credentials. Use the AuthUserFile directive to point Apache to the password file we created. Finally, we will require a valid-user to access this resource, which means anyone who can verify their identity with a password will be allowed in:
ServerAdmin webmaster@localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
See line on screenshot....and place on this line with indentation...Instructables will not display
AuthType Basic
AuthName "Restricted Content"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
See line on screenshot....and place on this line with indentation...Instructables will not display
Save and close the file when you are finished. Restart Apache to implement your password policy:
sudo service apache2 restart
The directory you specified should now be password protected.
Step 6: Modify Sudo Nano /etc/init.d/garagerelay
#! /bin/bash
# /etc/init.d/garagerelay
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting Relay"
# Turn 0 on which keeps relay off
/usr/local/bin/gpio write 0 1
#Start Gpio 0 or 17 in BCM out mode
/usr/local/bin/gpio mode 0 out
#Start Gpio 2 or 27 in BCM in mode with pull up
/usr/local/bin/gpio mode 2 in
/usr/local/bin/gpio mode 2 up
;;
stop)
echo "Stopping gpio"
;;
*)
echo "Usage: /etc/init.d/garagerelay {start|stop}"
exit 1
;;
esac
exit 0
Step 7: Make Motion Start at Boot
$ sudo nano /etc/init.d/cam_motion
Then paste the blob below.
#! /bin/sh
# /etc/init.d/cam_motion
# Carry out specific functions when asked to by the system
case "$1" in
start)
echo "Starting Camera Motion"
nohup /home/pi/mmal/motion -n -c /home/pi/mmal/motion-mmalcam-both.conf 1>/dev/null 2>&1 ;;
stop)
echo "Stopping Camera Motion"
killall motion
;;
*)
echo "Usage: /etc/init.d/cam_motion {start|stop}"
exit 1
;;
esac
exit 0
crtl o to save
crtl x to exit
Make it executable
$ sudo chmod 777 /etc/init.d/cam_motion
Make it start at boot
$ sudo update-rc.d -f cam_motion start 4
Reboot
Step 8: Bring Up on Web Browser Once You Setup Your Router Port Forwarding
Got one of those SmartPi cases for Pi and Camera that has Lego as a cover. Attached relay board to back of case with zap straps.
I put the magnetic switch at the top of the garage door and used some cat5 cable I had to bring it back to the Pi. Cut some jumpers in have and soldered to the cat5 one pair. Wrapped the extra pairs back.
Found really simple fix for Away and Home.
Setup the index.php that does the buttons and video etc to be for home like
Then make a copy of index.php to away.php still in the /var/www/ folder.
Edit away.php to be like
In your router:
Port Forward Wan port xxxx1 to Lan 80 of RaspiIP
Port Forward Wan port xxxx2 to Lan 8081 of RaspiIP
Now in your Browser at home or your cellphone:
At home use http://RaspiIP this will default to port 80 and index.php
When Away use http://YourDdnsAddress:xxxx1/away.php
Step 9: Final Result: Garage Control/monitor
I soldered a pair of wires across the back of the circuit board of a RF Garage opener. Put wires behind the bigger button as there already was a slot in the plastic. Putting the relay directly to the 2 wires between wall and ceiling unit just caused the wall unit to reset. Now the relay is the same as putting the visor remote.


