The situation is like this, I often play games and sometimes need to open the downstairs access control to let the delivery guy leave the food at the door. But I often need to switch out and open the mini program, and click to open the door.
This amount of time is enough for me to achieve a wonderful pentakill.
Can a lazy dog programmer endure this? No! So I wrote a door-opening service during my free time and deployed it on my k8s.
It has been running safely for over two months now.
Packet Capture#
Warning for the crime of destroying computer information systems
The simplest way is to open the mini program on the computer to obtain the request parameters and address of the mini program.
The token for users who frequently log in to open the door in the mini program access control remains unchanged...
The specific method of packet capture will not be discussed in this article.
Mi Home Third-Party Platform#
After subjective research, Bafa Cloud is currently the most suitable cloud platform.
The general process is as follows:
For specific Bafa Cloud service invocation processes, you can refer to the detailed documentation on the official website.
Taking door opening as an example here.
Create a new MQTT device cloud named FBIOPENTHERDOOR001. The numerical value at the end of the device name represents the type of device, and 001 represents the switch type.
Then go to the Mi Home app -> Mine -> Other platform devices -> Add -> Enter your Bafa Cloud platform account and synchronize the device.
At this time, when you say "open the door" to Xiao Ai, the subscribing end will receive a string "on". At this time, you can call your access control API to achieve the effect of voice-controlled door opening.
Precautions#
- Please note that when MQTT reconnects, you need to subscribe to the topic again.
- You can add an API retry mechanism to prevent the access control API from failing under certain special circumstances.
- Add a service restart mechanism. If you have k8s, ignore this. In some cases, the MQTT connection may be unstable and disconnected, requiring a restart.
- You can create your own access control API to forward missed calls through SmsForwarder to achieve door opening, to prevent oversleeping while waiting for late-night snacks. (Who overslept, I won't say 🤡)