Our thinking

The Slack #gate: how we automated our office’s parking gate

25 May 2016

Introducing PIGate! A web-service enabled garage door opener / electric gate opener. It’s essentially a RaspberryPi connected to a garage door opener.

We plugged PiGate into Slack. Say “go go gadget gate!” in our #gate channel, and the gate opens. Yay!

slack-gate-pigate

You could plug PiGate into any other web service, using IFTTT, Zapier, or a little custom coding.

I built the hardware and web services, and Zach poked a hole in our firewall and plugged it into Slack via Zapier. Here’s how we did it:

Connecting a RaspberryPi to a Remote

Required Knowledge

  • Rasberry Pi Basics
  • A little Linux wizardry
  • Willing to poke around with expressjs

Required Hardware

  • Raspberry Pi (gen 3 preferably)
  • 8gb+ microSD card
  • A relay module such as this one
  • The remote of course
  • Some wires
  • An enclosure to house the project. Something like this.

Tools

  • A soldering iron
  • Hot glue gun

Hardware Overview

pigate-insideThe idea here is simple, turn one of the Raspberry Pi’s gpio pin on via software to activate the remote which in turn opens the gate.

The standards I gave myself for this project were that it must be simple to use, require the least amount of components, and be reliable.

Hacking the Hardware

We could go down the route of conjuring up some bespoke circuit and piggybacking it onto the remote but that would mean limiting its use to that specific remote. The easiest and cheapest option is to use a relay breakout board. With a dual relay board costing only around $6 and having the added option to control a second appliance up to 10A it’s a no-brainer.

pigate-schematicPutting this all together is, for the most part, fairly straight-forward. The relay is essentially replacing the button on the remote, so by following the traces on the remotes PCB and soldering wires to the two pads that would otherwise be bridged by the button (marked in orange in the photo) and then attaching those wires to the normally open connectors on the relay board we are effectively bypassing the button.

pigate-schematic2From the Raspberry Pi two wires from the GND and 5v are connected to the respective GND and 5v(VCC) pins of the relay. The third wire goes from one of the gpio pins (in my case gpio 17) of the PI to either one of the IN1 or IN2 pins depending on which relay you attached to your remote. The gpio pin must be one of the pull-down pins as the relay operates by pulling the voltage of the pin to 0v and not by supplying the pin with a voltage which is somewhat counter-intuitive but there is good reason for this that I could go into in a later post (leave a comment if you’re interested!). With this the hardware is pretty much done only to put it into a nice enclosure and supply the power. In this case the remote operates at 9v so its original 9v pp3 battery is used. The Raspberry Pi is powered via its standard 5v micro usb power supply.

The RasberryPi Software

The software can all be downloaded from github. There you’ll also find more detailed set-up information. Here’s an overview of how it works:

pigate-loginThe web interface is an expressjs application running on the raspbian Linux distro. The program accepts a username and password via a post request and queries a mongodb database to for a match. Once everything matches up a system command is called which switches the gpio pin low for 1 second and then high again. The default username and pass is ‘user’ and ‘user123’.

The app is run using forever (so that is runs forever), and is included as a startup job in /etc/rc.local so in the event that the PI loses power or turns off it will start running again once the power is restored.

Since all that is needed is a simple post request to the web page with username and password it is very simple to integrate this into other applications. I have created a very simple android app to demonstrate this. The app has just one button which posts to a specified url your username and password.

The Mongodb instance is probably overkill for a small network of people, a config file to store the credentials would be enough in most cases – I plan to change that in the near future. I would like to add an interface to add or edit users.

A version of the software finished that uses a much simpler config file is available in the config branch of the github repo.

Connecting to a wifi network

If you have a monitor handy, connecting to wifi is as straightforward as logging in clicking the network icon and following the prompts. Without a monitor, it gets a little more complicated. We need to edit the /etc/wpa_suplicants/wpa_suplicants.conf  file. To do this we can connect the raspberry pi to the network directly using an ethernet cable and then find its ip address. With this we can connect to the pi via ssh “ssh pi@<ip address>” (default password: raspberry).

Once logged in we can edit the file using “sudo nano /etc/wpa_suplicants/wpa_suplicants.conf” and add the following text to the bottom.

network={
    ssid="YOUR_NETWORK_NAME"
    psk="YOUR_NETWORK_PASSWORD"
    key_mgmt=WPA-PSK
    }

Then “sudo reboot” and all going well, the pi should connect to the wifi automatically when its restarts.

Putting it in the box and mounting it

To keep everything nice and neat I mounted all the electronics inside an 8”x6” electrical junction box. A hot glue gun was used to hold everything in place making sure to position everything as not to obstruct the usb, ethernet ports etc. The junction box has rubber grommets around the edge which I pierced to allow the cable of the power supply to enter.  

Connecting Slack to the RaspberryPi

After I connected RasbperryPi to the exygy WiFi network and mounted it in the window we could hit the server from an internal 192.168.x.x IP address to open the gate.

We tunneled a hole in our firewall (thanks Earl at IT Jones!) so the web server had a permanent externally addressable IP.

We then plugged in Zapier. We created a new Zap. It started with a simple trigger for Slack: New Message Posted to Channel > #gate

The trickier part was getting the POST right. We used Zapier’s built in “Webhooks” actions. We created a POST with the following template:

URL: http://your-public-url.com:your-port/open

(eg: http://officegate.yourcompany.com:8080/open)

Payload type: JSON
username: yourusername

password: yourpassword
Wrap request in array: No

 

That’s it! Now just head on over to Slack, post in the #gate channel and you’re good to go!

Have fun 🙂