This article is the 20th day of Retty Advent Calendar 2019. Yesterday, Mr. Hirano's "Retty Data Analysis Team-Review of the Second Year of Launch-Data Platform / Data Democratization / Statistical Model- / 190000) ”.
Nice to meet you. I'm Koda, a 20-year-old engineer who is currently an intern at Retty.
For the time being, I was wondering what to write after registering for participation, but I made my own entry / exit management system (electronic lock) that is operated in the laboratory of the university I attend, so I will talk about that.
We received a lot of opinions from Hatena bookmarks. Thank you very much. As some people have pointed out, the reaction on Slack when the problem "I couldn't get out of the room at night" occurred was inappropriate, so I deleted it. I regret that it was not appropriate to take up such contents in the blog. Also, since we have not taken measures in the event of an unexpected situation such as an earthquake or fire, we would like to consider a mechanism that can be unlocked in an emergency.
Immediately after I was assigned to the laboratory, I was asked what to do with the room key.
When it comes to making duplicate keys for the number of people, it costs a lot and it is troublesome to manage the keys for the number of people. When the total number of third-year students reaches about 20, some people will lose it.
Next, I thought about introducing a smart lock like Qrio, but the door of our laboratory was not compatible with the thumb turn "type with doorknob". (Other supported thumb turns are summarized in detail on this page.)
As far as we know, there is no smart lock product for this type, which raises the bar for door IoT considerably.
I had no choice but to make it myself, so I decided to make it. [^ 1]
The final composition looks like this. I made it as I like with the technology I want to use.
The electronic lock body is a RaspberryPi3 Model B +
with a servo motor, reed switch, and card reader connected. The program that controls the servo motor was written in Python.
Two card readers are used, and by attaching them to the inside and outside of the door, the state of in the room
or going out
is managed. I will explain why I manage it later.
In order to make it ** auto lock **, a reed switch is attached to acquire the open / closed status of the door.
We registered the student ID card and ICOCA ʻidm` that everyone has in the database and authenticated them as a key. We haven't made it compatible yet, but if you make it compatible, you can unlock it even with a card registered with Apple Pay.
As a secondary benefit, "** You can reduce the risk of losing your key **". This is because if you delete the target data from the database, you will not be able to enter or exit with that card.
It was maddox / dasher
that was often used when the Amazon Dash Button hack was popular, but when I looked into the repository for the first time in a while, Nekmo / amazon-dash
was mentioned.
All settings can be written in yaml
format, and a Docker image is also available.
The "** in-room display board (whiteboard) **" that is familiar in university laboratories seems to be good by using an electronic lock, so I made it good.
It will be explained in the next function introduction.
I would like to introduce it because it has some functions, not just moving as an "electronic lock".
I made a simple management screen with Flask
to register / edit / delete members.
Everyone loves the front desk, Bootstrap + jQuery
.
By the way, you have to look up ʻidmyourself and then enter it manually. If you use
WebUSB` or something, you can connect a Felica reader, read it from there, and register it, but I haven't implemented it yet.
We have made it possible to see the occupancy status online so that you can see who is from anywhere. A monitor is installed at the entrance with a monitor arm, and another RaspberryPi is used to create a kiosk terminal for display. It's convenient because you don't have to move the magnet on the whiteboard.
When you press the button on the door, you'll hear this message on Slack's notification channel. It is linked with Slack's Interactive Components, and by pressing "Unlock", you can unlock without having to go to the entrance to pick up. I will. By the way, in this case, you will be asked to open the door and come in by yelling "Key is open!" From your seat in a loud voice.
You can stay away by pressing "Ignore".
As shown in the image, a log of "who responded" remains. The message is overwritten, so it's nice to see the Slack notification badge disappear when someone responds.
I devised a little part to connect the unlock button of Slack and RaspberryPi.
Specifically, when the Slack button is pressed, Slack sends a POST
request to the endpoint you specified, and it's about where to put this endpoint.
It seems quick to set the endpoint directly on the RaspberryPi, but I didn't want to expose the electronic lock to the Internet, so I decided to put MQTT
in between.
For MQTT and MQTT broker, "First MQTT" was easy to understand, so I will post it.
First, set up an API to receive requests from Slack, and when you receive a request that "the unlock button has been pressed", publish
to the target topic
.
By subscribing
the same topic
on the RaspberryPi side, it is possible to detect the occurrence of an event without exposing it to the Internet.
I thought it would take some time to unlock, but is it practical because it unlocks in about 1 second after pressing the Slack button? It was within the range.
One day around 20:00, while working at home, I received a visit notification from the call button in the laboratory.
Apparently, the teacher remained on this day, and he went out for a while with the lights on. Most of the visits during this time are guards, and they come when the lights are on. ~~ I will get angry at a later date if there is no one left on. ~~
The moment I received the visit notification, I thought "Ah" and turned off the lights remotely. [^ 2]
After this, the title incident happened.
** When the guard entered the laboratory and checked the room, I just turned off the lights **, and he was panicking ... Furthermore, ** it was locked by auto-lock while checking the room **.
I had a button that can be unlocked from the room for a while, but it didn't seem necessary, so it happened immediately after I removed it.
Mr. Mamoru, I'm really sorry for making you scared.
[^ 1]: It was NG from the university side to replace the entire doorknob. [^ 2]: Lighting is also IoT. Originally, it is a function that automatically turns off at a fixed time in case you forget to turn it off.
Recommended Posts