Table of Contents
The doorbot is responsible for scanning key fobs and unlocking the door for members. The software is written in Typescript and deployed to a Raspberry Pi. It expects to use the Wiegand protocol for reading fobs.
Implementation of the system is split up into a few repositories:
- https://github.com/frezik/doorbotts - The base system
- https://github.com/frezik/rpi-doorbot-ts - Raspberry Pi-specific code
- https://github.com/bodgery/bodgery-doorbot-ts - Bodgery-specific code
- https://github.com/bodgery/bodgery-doorbot-deployment/tree/edd - Deployment code
- https://github.com/frezik/wiegand_pigpio - Weigand reader
There are currently two doorbots. “Edd” takes care of the cleanroom doors, and “Hodor” is in the woodshop. These both check that keys are valid using “Tyrion”, the main server for the member database.
Building a Doorbot
A new doorbot can be built with the following components:
- 12V power supply: https://www.amazon.com/gp/product/B00D7CWSCG/ (if only driving a single solenoid lock, this can be slimmed down to 10A, or even 5A)
- 4x power supply holders: https://www.thingiverse.com/thing:2062755
- 120V power socket w/switch: https://www.amazon.com/URBEST-Module-Switch-Socket-IEC320/dp/B00ME5YAPK
- 5V voltage converter: https://www.amazon.com/gp/product/B00J3MHRNO
- Micro-USB cable (can be short)
- 3/8“ plywood sheet, 2'x4'
- Raspberry Pi (a multicore model is strongly recommended)
- Raspberry Pi mounting bracket: https://www.thingiverse.com/thing:2480304
- Raspberry Pi prototype breakout board: https://www.amazon.com/gp/product/B07BF8Z3HS
- SD card (8GB or more, recommend A1 rated or better)
- DB9 port breakout board pair: https://www.amazon.com/gp/product/B071ZLNDYT
- Mounting bracket for DB9 (you'll need to use OpenSCAD to convert this to an STL): https://github.com/bodgery/bodgery-doorbot-ts/blob/master/hardware/cable-mount.scad
- 120mm computer fan: https://www.amazon.com/ARCTIC-F12-Standard-Configuration-possible/dp/B002KTVFTE
- Red and Black hookup wire
- Breadboard breakoff pin headers
- Wood screws that won't poke through the plywood when you screw in the mounts
- 4-pin molex computer connector
- C13 power cable (standard computer power cable): https://www.amazon.com/gp/product/B005WKJQ4E
First, make the box by cutting the plywood on a laser cutter using this pattern: https://github.com/bodgery/bodgery-doorbot-ts/blob/master/hardware/bodgery-doorbot-box.svg. Run off all the 3D printed parts (power supply holders, Pi bracket, DB9 bracket). Install Raspbian to the SD card.
Using the brackets, screw down the power supply and Raspberry Pi, as well as the 5V power converter and the fan. The Pi should be placed near the open slot in the back, so you can plug in an Ethernet cable later.
Cut the end off the micro-USB cable, with enough length to run between the Pi and the 5V power converter. Connect the power wire (usually red) to the 5V output, and the ground (black) line to ground. Use hookup wire to connect the 12V output from the power supply to the input of the 5V converter, as well as the ground line.
Connect the 12V line of the molex connector (yellow wire) to the 12V power supply output, as well as the two central ground pins on the connector. Connect this to the fan.
Connect the hot/neutral/ground wires of the power supply to the plug. WARNING: These connections will be handling 120V power. Be sure they are well insulated and appropriately sized.
At this point, you should be able to plugin everything and have the Pi bootup.
The DB9 port connects the box to the components being controlled. Although it should work as long as you connect up both sides the same, it's best if we keep all the doorbots in the shop the same. Here's the recommended pinout:
- Wiegand Data 0
- Wiegand Data 1
- Door Latch
Wiegand Data 0 should go to the Rasbperry Pi's GPIO 12, and Data 1 should go to GPIO 13. Door Latch should go to the breakout board's MOSFET.
Raspberry Pi Breakout Board
Here's a wiring diagram for connecting the Pi:
Connect header pins on GPIO12 and 13, plus two for the door latch. You'll also want pins for an incoming 12V input and its ground. Add a few more pins for the 5V, 3.3V, and the Pi's ground.
Here's an example of a completed board:
This board has a few extras, like a jumper pin that could go to a switch, allowing power to be entirely cut to the latch (which might be useful for a magnetic hold system). There's also an LED indicator coming off an extra GPIO pin.
Installing the Software
The Raspberry Pi will need git and Node.js installed. The wiegand reader also needs the pigio library. Install typescript globally
$ sudo apt-get install nodejs git pigpio
$ sudo npm -g install typescript ts-node
Then, clone the deployment repository, branch “edd”:
$ cd bodgery-doorbot-deployment
$ git checkout edd
Install all the dependencies
$ npm install
Copy the systemd startup file, and set it to start at boot:
$ sudo cp rfid.service /etc/systemd/system/
To get the tight timings required, using a C program to read the Wiegand data tends to be more reliable than doing it in Typescript. So we'll install that:
$ git clone https://github.com/frezik/wiegand_pigpio.git
$ cd wiegand_pigpio
$ make && sudo cp wiegand_c /usr/local/sbin/
The cache file should go in a tmpfs. Create the directory for this:
$ sudo mkdir /var/tmp-ramdisk
$ sudo chmod 777 /var/tmp-ramdisk
And add this line to
tmpfs /var/tmp-ramdisk tmpfs nodev,nosuid,size=100M 0 0
Install some dependencies for the cache update script:
$ sudo apt-get update
$ sudo apt-get install cpanminus
$ sudo cpanm Sereal::Decoder LWP::UserAgent Cpanel::JSON::XS LWP::Protocol::https
A username/password will need to be assigned to the box, which is created on the nginx frontend running on
margery0. You should then set them at the top of
Add it to the crontab (with
1 * * * * perl /home/pi/doorbot/update_cache_file.pl > /dev/null
Which will update the cache file hourly.
Finally, start the whole thing running:
$ sudo systemctl start rfid
And have it start at boot:
$ sudo systemctl enable rfid