Next Stop - Ihcblog!

Some creations and thoughts sharing | sub


Little DIY - Create a More Comfortable Student Dormitory

This article also has a Chinese version.

This article will introduce some of the projects I undertook during my undergraduate years to make my dorm room more comfortable, including setting up the door to be opened with a smartphone and making it more convenient to watch videos.

The entire code(excluding code and models that I don’t have permission to publish) can be found on GitHub.

Smart Door Lock

The door lock in my undergraduate dorm was somewhat strange; both locking and unlocking required a key. Without locking it, the door would be susceptible to wind, creating a noise nuisance. This was particularly troublesome for someone like me who frequently ordered takeout.

After investigating the lock, I found out that it actually supported key card access. However, previous cohorts of students had discovered that by prying open the card reader and shorting one of the wires, they could unlock the door—a clear design flaw since it placed control wiring within the user-access area.

After disassembling the lock, I exposed the 12V power supply and control wire. This control wire simply needed to be triggered and didn’t require any external management of the relay timing. So, the integration with my own system was straightforward—I just needed to connect the 12V power and then use an additional relay to control the wire (since we commonly use 5V or 3.7V boards).

I used a Raspberry Pi + Arduino + 5V relay to accomplish this task. I connected an Arduino via serial because the relays I bought operated at 5V.

Smartphone Door Opening

Once the Raspberry Pi was set up to control the lock, it was necessary to build a user-friendlier system.

I used the WeChat public platform for this, and after configuring the address, our server was able to receive user messages sent from WeChat servers. However, to relay these messages to the Raspberry Pi, it was necessary to tunnel into the internal network.

Our dorm didn’t have its own broadband connection but instead freeloaded off the campus network using a VPN connected to the lab. This meant we didn’t have a public IP. The solution was either to connect to a VPS via VPN or to find a way to map requests to the internal network. For reliability, I chose to use the CTF team’s domain for redirecting into the school’s network—admittedly, a bit inappropriately. This effectively allowed the school to perform the internal network access on my behalf. Since the CTF team’s host was multi-user and not entirely trustworthy, I set up a channel that went WeChat -> VPS -> -> Dorm internal network IP.

For the authorization, I used the Google Authenticator algorithm which generates keys valid for half a minute based on time and a predefined secret.

Too Lazy to Pull Out Your Phone?

At this point, we could unlock the door ahead of time while leaving the elevator. But what if you are too lazy to even take out your phone?

Wi-Fi was the answer. I ran a monitoring script on my router to watch for MAC addresses of mobile devices that connected.

I set the conditions for opening the door to be new device connects && the device is listed in specified devices && the time since the device last disconnected exceeds t minutes && dbm < threshold && the current time is appropriate. This way, when I went out to pick up delivery during the day, the door could automatically unlock upon my approach.

(This was a project from three years ago, and I had many photos that I can’t find anymore.)

Facial Recognition?

But what if I forgot my phone? Hence, I installed a camera above the dorm’s door. When it detected movement, it took a picture and uploaded it to the university’s server, where I utilized the GPU for facial detection and comparison (as I already had related code and models from previous work at Shanghai Advanced Research Institute). However, due to overall stability and high latency issues, and lacking liveliness detection mechanisms, I didn’t put it into practice.

Today, facial recognition services are commonplace. Ignoring the need for liveliness detection, it might be as simple as using someone else’s API.

Watching Videos Peacefully

Fudan’s PT (private tracker) was a treasure trove of resources, and it was generally very comprehensive for series and movies. However, these video resources were often raw files without hard-coded subtitles, which meant having to download and load subtitle files manually—quite inconvenient.

Automatic Subtitle Download

The video player provided by Thunder (Xunlei) could automatically download subtitles, which made me quite curious about how it worked. After capturing some network traffic with Wireshark and analyzing online resources about Thunder’s hashing algorithms, I was able to use the video file to directly download the appropriate subtitles. (See V2EX post)

However, running scripts manually was also troublesome. Since I was using aria2 for downloading, I could simply monitor *.aria2 files. When these files were deleted, it indicated that the download was complete. By checking the file extension, I could automatically download the corresponding subtitle file—a process facilitated by the inotify library. (For the full code, visit GitHub)

You can install this tool easily with pip install subtitle, and then simply use the command sub ABC.mkv to automatically download the subtitles related to the video.

Automatic Download for Mobile

It’s so comfortable to watch videos while lying in bed… but downloading them still requires open PT->download torrent->open aria2 web UI->upload torrent.

This wouldn’t be much of an issue with an Android tablet, but iOS is notoriously unfriendly when it comes to file downloads. So, the solution was to write something that could accept PT torrent links and automatically download the torrents on my behalf!

This, too, was quite simple. I quickly set up a little website just for my personal use using Flask, and restricted access based on IP address through Nginx. Upon receiving a PT torrent link, the system would automatically log in, download the torrent, and upload it to Aria2 using Aria2’s JSONRPC.


It’s been over a year since graduation, and I still miss those undergraduate days.

Welcome to my other publishing channels