I became quite interested in servers running in python after my first exposure to Django. I thought I’d put my Raspberry Pi to good use by making an automatic door opener for my flat.
The street entrance to my building is controlled by an archaic intercom/buzzer system. Say a person with a delivery for me wishes to enter the building, the person would press the button corresponding to my flat, which would ring my intercom unit, I can then press a button to open the lock. The problem arises when I am outside, i.e. any delivery attempt will result in a return to depot because they can’t gain access to the building and ergo not be able to leave the item safe.
To be able to control the intercom remotely.
As it turns out, the ancient nature of the intercom is to my benefit. There’s an analogue circuit that simply creates a short between two of the five leads going to my unit. This means I only need a small 5V relay to control the door unit. With a python code of something like this:
import RPi.GPIO as GPIO pin = 21 import time GPIO.setmode(GPIO.BCM) GPIO.setup(pin, GPIO.OUT) GPIO.output(pin, GPIO.HIGH) time.sleep(2) GPIO.output(pin, GPIO.LOW)
I then wrote up a really simple flask server that accepts POST requests.
from flask import Flask from flask import request import requests import os app = Flask(__name__) KEY = "KEY WITHHELD" @app.route("/") def home(): return "<h1>Door control server is operational.</h1>" @app.route("/opendoor", methods = ["POST"]) def sesame_door_open(): password = request.get_data() password = password.decode("utf-8") if password == KEY: os.system("cd ~/Desktop | python3 opendoor.py") print("Door Opened") return "" if __name__ == '__main__': app.run(debug=True, host ='0.0.0.0')