GaragePI Update with Camera and Node.js
It's been over a year since I first made the GaragePi, a garage door opener made with a Raspberry Pi, and since then, it's come in handy in quite a few situations. Like when going on vacations or even a bike ride, I can leave my keys at home. I've also made the following enhancements:
- rewrote the server using Node.js
- added a camera module to take a snapshot of the garage door
- removed the battery in the garage remote and wired it directly to the Pi
Node-GaragePi Installation Instructions
The reason for the Node.js rewrite was just a personal preference and not anything against Python. Since I also have other node apps running on the same Pi, it just makes things a bit easier to manage.
Download and install Node.js and NPM:
wget http://node-arm.herokuapp.com/node_latest_armhf.deb sudo dpkg -i node_latest_armhf.deb
Check the install worked correctly by typing the command below:
The next steps are to set it up so the GPIO pins can be used by your logged in account instead of root as it normally requires:
git clone git://github.com/quick2wire/quick2wire-gpio-admin.git cd quick2wire-gpio-admin make sudo make install sudo adduser $USER gpio
After this, you need to simply log out and then log back in.
Next, we'll download and setup Node-GaragePi:
cd ~ git clone git://github.com/chasechou/node-garagepi.git cd node-garagepi npm install
That should install the required modules and you can test it all out by running:
Load up http://192.168.1.60:8000 in a browser to see if it's working. Change the IP to that of your machine if it's different.
[update 8/2/15] If you see an error like this:
[[23:45:47]] [ERROR] gpio-admin: failed to change group ownership of /sys/devices/virtual/gpio/gpio4/direction: No such file or directory
Then you'll need to also patch gpio-admin because at some point, Raspbian changed the path to something gpio-admin is expecting. The patch is described here and we can easily make the necessary edit manually:
cd quick2wire-gpio-admin/src vi gpio-admin.c
Change this line:
int size = snprintf(path, PATH_MAX, "/sys/devices/virtual/gpio/gpio%u/%s", pin, filename);
To this instead:
int size = snprintf(path, PATH_MAX, "/sys/class/gpio/gpio%u/%s", pin, filename);
Then simply run the following commands back in the quick2wire-gpio-admin root dir just as we originally did above:
sudo make uninstall sudo make install sudo adduser $USER gpio
Logout then back in and re-run the node app and the error should not happen again.
If that all looks correct, then the last step is to set it up so it runs on boot up. I chose to use PM2 as the process manager as I've had some good experience using that in other projects.
sudo npm install -g pm2 sudo env PATH=$PATH:/usr/local/bin pm2 startup raspberry -u pi cd ~/node-garagepi pm2 start garagepi.js -x --name "node-garagepi" pm2 dump
Then restart your Pi again to test that it automatically started the app by loading it up in your browser.
Adding the Pi Camera Module
The camera module was for added so I can visually check the state of the garage door. I highly suggest adding a camera if you plan on using GaragePi remotely. I bought this camera:
The setup was pretty straight-forward and the directions I followed was this below:
Node-GaragePi is already setup to take a snapshot every 30 seconds and uses that as the background image of the page. The image is saved at ~/node-garagepi/public/images/garage.jpg.
Replace the Garage Door Remote Battery
And, lastly, the battery hack was the most important one of all. In the past year of running GaragePi, I found that I had to change the battery in the remote 2 or 3 times. Even with light usage I found the battery was drained to the point where it couldn't actually open the garage door after only a few months. This modification makes it so the battery is no longer needed.
The idea is simple. My garage door remote uses a CR-2032 coin shaped battery that is 3.3V. The Pi just so happens to have a 3V terminal that should be free to use. So simply remove the battery from the remote and wire the positive terminal on the remote to the 3V pin on the Pi and the negative to a GND on the Pi.
That should be it. No more worrying about the battery as long as your Pi is powered up!
Let me know how it goes... good luck and have fun!