As soon as @bourryto and I moved into our flat share, we wanted to improve our key sharing and door opening concept,
What do I need?
- A Raspberry Pi Zero W
- and obv a MicroUSB plus brick and a MicroSD
- 5V/220V 2 Channel Optocouplers Relay Module
- I bought some cheapish ones off eBay
- Jumper Wires
- mine are ace-colored, this wasn’t intended
How to set these things up?
Building a working set-up with this was quiet easy, unless you still want to use a physical button to open the door, that would require some soldering, you bascially just have to:
- make sure which two cables are being used for the strikes button mechanism
- connect the wires to the relay and the relay control pins to the Raspberry Pi
If you’re using RPi.GPIO in python and let’s say the GPIO-PIN 17 you’re most likely to open your door now via:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
# import things import RPi.GPIO as GPIO import time # config relay things GPIO.setmode(GPIO.BCM) CONTROL_PIN = 17 GPIO.setup(CONTROL_PIN, GPIO.OUT) GPIO.output(CONTROL_PIN, GPIO.HIGH) GPIO.output(CONTROL_PIN, GPIO.LOW) # open the door time.sleep(3) # remain in this state for three seconds GPIO.output(CONTROL_PIN, GPIO.HIGH) # close the door again [even more code]
But isn’t it annoying having to SSH on your Pi via VPN/Local Network at first?
Yes it is, and we want to use functions as well since the script above is really low effort.
So here’s a better one:
Introducing pink fluffy gunicorns
Using the development server of flask isn’t recommended for production use. So we’re going to need a callable WSGI application object:
and a systemd service file:
If you enable and start the service you’ll spin up a webserver running on port 5000.
How to use the web service?
xx.xx.xx.xx:5000/opento open the door
xx.xx.xx.xx:5000/closeto reset/debug the door
xx.xx.xx.xx:5000/infoto show the info page