{"id":141,"date":"2021-07-21T10:40:04","date_gmt":"2021-07-21T10:40:04","guid":{"rendered":"https:\/\/patrickwang.co.uk\/?p=141"},"modified":"2021-07-21T10:41:15","modified_gmt":"2021-07-21T10:41:15","slug":"automatic-door-opener-for-my-flat","status":"publish","type":"post","link":"https:\/\/patrick.scot\/index.php\/2021\/07\/21\/automatic-door-opener-for-my-flat\/","title":{"rendered":"Automatic Door Opener for My Flat"},"content":{"rendered":"\n<p>I became quite interested in servers running in python after my first exposure to Django. I thought I&#8217;d put my Raspberry Pi to good use by making an automatic door opener for my flat. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Background<\/h2>\n\n\n\n<p>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, <em>i.e.<\/em> any delivery attempt will result in a return to depot because they can&#8217;t gain access to the building and <em>ergo<\/em> not be able to leave the item safe. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">The Goal<\/h2>\n\n\n\n<p>To be able to control the intercom remotely.<\/p>\n\n\n\n<p>As it turns out, the ancient nature of the intercom is to my benefit. There&#8217;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:<\/p>\n\n\n\n<pre class=\"wp-block-code language-python line-numbers\"><code>import RPi.GPIO as GPIO\npin = 21\nimport time\nGPIO.setmode(GPIO.BCM)\nGPIO.setup(pin, GPIO.OUT)\n\nGPIO.output(pin, GPIO.HIGH)\n\ntime.sleep(2)\n\nGPIO.output(pin, GPIO.LOW)<\/code><\/pre>\n\n\n\n<p>I then wrote up a really simple flask server that accepts POST requests.<\/p>\n\n\n\n<pre class=\"wp-block-code language-python line-numbers\"><code>from flask import Flask\nfrom flask import request\nimport requests\nimport os\napp = Flask(__name__)\nKEY = \"KEY WITHHELD\"\n\n@app.route(\"\/\")\ndef home():\n\treturn \"&lt;h1>Door control server is operational.&lt;\/h1>\"\n\n@app.route(\"\/opendoor\", methods = &#91;\"POST\"])\ndef sesame_door_open():\n\tpassword = request.get_data()\n\tpassword = password.decode(\"utf-8\")\n\tif password == KEY:\n\t\tos.system(\"cd ~\/Desktop | python3 opendoor.py\")\n\t\tprint(\"Door Opened\")\n\treturn \"\"\nif __name__ == '__main__':\n\tapp.run(debug=True, host ='0.0.0.0')<\/code><\/pre>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I became quite interested in servers running in python after my first exposure to Django. I thought I&#8217;d put my Raspberry Pi to good use by making an automatic door opener for my flat. Background The street entrance to my building is controlled by an archaic intercom\/buzzer system. Say a person with a delivery for [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-electronics"],"_links":{"self":[{"href":"https:\/\/patrick.scot\/index.php\/wp-json\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/patrick.scot\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/patrick.scot\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/patrick.scot\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/patrick.scot\/index.php\/wp-json\/wp\/v2\/comments?post=141"}],"version-history":[{"count":3,"href":"https:\/\/patrick.scot\/index.php\/wp-json\/wp\/v2\/posts\/141\/revisions"}],"predecessor-version":[{"id":144,"href":"https:\/\/patrick.scot\/index.php\/wp-json\/wp\/v2\/posts\/141\/revisions\/144"}],"wp:attachment":[{"href":"https:\/\/patrick.scot\/index.php\/wp-json\/wp\/v2\/media?parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/patrick.scot\/index.php\/wp-json\/wp\/v2\/categories?post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/patrick.scot\/index.php\/wp-json\/wp\/v2\/tags?post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}