A Friday Hacks project adding an NFC/RFID lock system to our local office, powered by a Raspberry Pi 3 and resin.io
This project took longer than I expected, partly because I was trying a few different ways that would allow us to unlock the office door. One such attempt was using a Lockitron, but that would have meant that we couldn't unlock the door with a key anymore and that was just not going to work.
One enhancement that I wanted to add was support for encrypted key cards, such as Oyster, Apple/Android Pay and contact less bank cards. This required removing some checks from the Adafruit PN532 library. My version ignores invalid check sums instead of crashing with an error (which happens in the original library when reading these cards).
I plan to add a Flask server to the script, which can be exposed over a public device URL and would provide an API endpoint to open the door remotely. This can be combined with our Hubot such that the door could be opened by asking it on our company chat: hubot open the office (possibly adding some magic keywords for security, such as please - or something more secret)
I might also add a front-end that shows who is in the office, based on their card login - although this may be slightly Orwellian.
I chose to set up a Python script to implement the door lock logic. The source code is available on GitHub. The script has a straightforward (somewhat simplified) cycle of:
The script is deployed through resin.io, which allows some practical benefits. First, we can observe the logs from the lock script through an online dashboard and see entry attempts including tag IDs. This is handy when adding a new ID to the system as no additional equipment is needed: just scan and check the logs. Second, new card/tag IDs are authorized through adding environment variables in the dashboard (setting a series of variables such as CARD_1 , CARD_2 , ... containing the IDs), so no additional programming is required!
There are additional settings, such as how long to keep the door open, or how fast to blink the LEDs.
The design I ended up with is based on a Raspberry Pi 3, and uses an Adafruit PN532 NFC/RFID reader, a NeoPixel LED ring, a Grove relay from Seed and a couple of other small parts (see the full bill-of-materials on Github).
For the action of actually opening the door, I've modified the office buzzer system to allow operation via a relay, whilst the usual button press works too.
The NFC reader, LED ring and the relay are all controlled by the Raspberry Pi through the GPIO pins.
The whole setup is placed behind one of our front windows and a poster, so it's not visible from the outside, but tags and cards can still be brought within reach of the reader.