# 1. Project requirements
At present, there are two main categories of electric locks on the market. One is home door locks connected to the Internet via wifi, and the other is office door locks that are unlocked by swiping cards or fingerprints. This project focuses on unlocking in dormitory scenarios, sending unlocking commands and reporting events through 2G networking. Through mobile applets, functions such as remote unlocking, unlocking authority sharing, and viewing unlocking logs can be realized.
# 2. Technical planning
## 1. Hardware
The hardware uses Shanghai Hezhou's Air202 module and is programmed in lua language. The power supply uses a wide voltage of 5-12V, and the onboard DC-DC buck regulator circuit converts the input power to 4.2V for the module. The buck regulator chip uses the JW5033 chip recommended by Hezhou.
## 2. Cloud platform
The cloud platform uses Alibaba Cloud's Internet of Things platform as the IOT device access platform, uses Mysql database to store permission data, device logs and other information, and uses function calculation to process information flow. When a mobile device sends an unlock request, it first reaches the API gateway, which calls the function calculation, performs authentication, and verifies that it is correct before sending the unlock command to the IoT platform. Separating the business layer from the access layer can greatly improve the working stability of the device and increase the message throughput in scenarios with large concurrency and large connections.
## 3. Mobile terminal
The mobile terminal is developed using the Uni-APP framework and the Vue language. It can run in environments such as WeChat applets and QQ applets, reducing the difficulty of multi-platform porting. The mobile terminal uses HTTPS to request data such as device lists, and uses MQTT to establish a connection with the IoT platform to achieve two-way communication from the mobile terminal to the device terminal.
# 3. Project design
# 4. BUG road
## V1
According to the original conception, it was initially planned to use the Air202+DC motor solution to drive the door lock knob to rotate through the DC motor to open the door.
![1596633081373.jpg]

After welding and debugging, I found that this version has the following problems:
①There is no onboard motor driver chip, and an external L298N driver module is required. The size is large, and L298N is suitable for driving dual-channel motors, which is a bit overkill.
②The board is slightly large, and all components are on one side.
## V2
Based on the above problems, the A4950ELJTR-T chip is drawn into the board, and the SIM card holder and its peripheral circuits are moved to the bottom layer of the board (mainly considering the use of the built-in card solution, the SIM card holder is retained for scalability, and the normal SMT only needs to be pasted on the front to reduce costs). Proofing, welding, and debugging are shown in the following figure
![1596633128959.jpg]

Actual installation and debugging found that the mechanical transmission part is unreliable. Because the knob needs to be driven by a motor, a low speed and high torque should be selected. Considering the overall cost performance, we finally chose a 12V 40r/min motor. The actual test found the following two problems:
① The transmission between the motor flange and the door lock knob is unreliable. We tried kite lines, fishing lines, iron wires, etc., and all had more or less problems. If the transmission material is too hard, it will hinder the door opening, and if it is too soft, it will cause the wire to tangle.
② When the motor rotates forward to open the door, the resistance is large and the speed is slow; when it is reversed, the resistance is small and the speed is slow. When performing the door opening operation, it rotates forward first and then reverses, and it is difficult to return to the previous position, resulting in manual correction after performing several door opening operations, which is not very practical.
## V3
Since I don’t have a 3D printer, it is difficult to debug quickly and repeatedly on Taobao proofing. Considering the time cost, I finally decided to change an electric control lock, so I started a major hardware transformation.
First, remove the original door lock
![1596633159680.jpg]

Then polish the door frame (the two locks have different lock tongue heights)
![1596633169516.jpg]

Install the new lock
![1596633179688.jpg]

Weld the new board
![1596633196529.jpg]

(After welding, I debugged for a long time before I found that there was a network that was not connected, so I manually flew the wire)
![1596633215158.jpg]

(Air202 is too expensive, so I removed one from the previous board)

V2 and V3 size comparison
![1596633237750.jpg]

Compared with V2, V3 has the following changes:
1. The firmware burning interface is changed from pin to electric contact
2. A 12V power supply port is added for the electric lock
3. The motor driver chip and its peripheral circuit are removed, and one IO port is pulled up to 12V through a transistor to provide an unlocking signal for the electric lock
4. The PCB size is reduced so that it can be inserted into the electric lock
(here is a photo & video of the final success)
# 5. Future planning
So far, the main technical route achieved through 2G has been run through, and it can be improved in the future through the following aspects:
## 1. Adapt more sensors
## 2. Adapt more networking methods
The current networking method used is 2G, which has the main advantage of low cost, but its bandwidth rate is also low, power consumption is high, and 2G is about to be decommissioned. Considering the current network coverage, 4G and wifi networking can be added later to cover more application scenarios. For 4G, you can choose Hezhou 724G. This module uses Cat networking, has small size, low power consumption and high bandwidth. It can not only be used for data acquisition and control, but also for some low-bitrate video scenarios.