- Process overview:
- Hardware design
- Communication Design
- Main control system design
- Multimedia system design
- Cloud support system design
- NAS storage system design
- RNN realizes light control
- Tmall Elf Access
Based on Home Assisstant, build a smart home with integrated home lighting system, multimedia system and water flow system. Technical points: Tmall Genie interaction, LoRa communication, MQTT protocol, FRP intranet penetration, NAS storage, and toggle switch circuit transformation.
大一暑假，开始尝试使用WiFiduino在家中控制一些物体，实现了对（坏了的）太阳能加水（通过电磁阀）的控制（修改了原先家里的管道，加入了电磁阀。跑了好多趟五金店，收获了不少关于水管的知识和实践经验。之后做surf的水泵也有用到。）以及对走廊灯（通过光电耦合器）的控制。找到一台废弃的10年前的我爸的IBM笔记本，装上了win server 2008, 并配置好了mysql数据库，并定期使用http从单片机采集数据。我用php写了一个简单的web界面，来展示相关信息，并实现网页控制。由于家里被分配的是中国移动分配的大NAT内网IP，因此使用frp来实现内网穿透，使外界可以访问家里服务器上的web网页。
大二暑假，基于本学期经验，重构系统。在服务器上，重装系统为Centos7使用home assistant 开源项目提供UI等服务，使用mqtt作为通信协议。使用nodeJS编写了灯控自动化和太阳能加水的控制逻辑。在单片机，更新了固件，支持ota远程更新固件（参考了部分wiot经验，但更加因地制宜）。此外，新增了两个流量计，以实现太阳能加水完全自动化（之前是通过网页设置加水时长）。由于流量计WiFi信号弱，我们使用了Arduino uno + LoRa作为通信手段。本次设计，结合爸妈的意见，充分考虑了整体系统的稳定性。比如，如何handle各种类型的错误和失联，如何在断电后丝滑得重启，如何在服务器无响应情况下保证单片机不紊乱，如何在系统失控后物理切回到手动（比如灯，和太阳能加水）。
大三暑假，基于过去积累的传感器数据，使用LSTM模型，通过keras+tensorflow训练神经网络，实现对灯控状态的预测。目前仍在持续优化中，预计9月前完成。此外，有计划接入天猫精灵的打算（仍在队列中，需等待ushio oauth系统的研发，ushio oauth系统需要等待ushio user系统研发，ushio user系统需要稳定的js-session作为支撑，js-session需要使用fp来精确识别用户设备。。目前fp仍处于第三测试阶段。所以，一步一步来吧，，）。
使用Arduino UNO作为计算单元。一方面，Arduino Uno拥有高可靠性，我之前的智慧窗帘系统使用Arduino Uno作为主控板，平稳运行1年半未出现硬件问题。另一方面，Arduino Uno拥有较大的RAM，无需为了争夺RAM而在单片机编程上煞费苦心。
使用安信可 LORA RA-02 LORA作为LoRa节点和LoRa网关通信模块。原因是surf项目使用的就是这个模块，比较了解它。
使用python3开源项目Home Assistant 为基础搭建本项目的主控系统。效果如下图：
- 使用WiFi，LoRa双协议。WiFi用于连接距离路由器较近的单片机，LoRa 连接距离较远WiFi信号弱的原处的单片机。
Combining the knowledge I have learned and using cutting-edge technology to benefit life has been my unremitting pursuit for a long time. In order to let my family experience a more stable, comfortable and intelligent lifestyle, and to consolidate the technical foundation and architecture experience accumulated in the school smartfarm project and my own ushio system, I decided to use 20 to 23 before going abroad. All day long, reconstruct the old IoT system at home. Adopt a layered architecture and interface-oriented, test-oriented, and document-oriented development principles, with Available and Reliable as the highest priority indicators to build an operational target 3. A highly modular, easy-to-remote control, open source home software and hardware intelligent sensor control system for more than years.
In the first semester of the freshman year, I was new to MCU and used Arduino Uno to build a smart curtain system in the dormitory (for details, please refer to this blog -on-wifiduino.html)), has accumulated a certain amount of experience.
- Ask experts (for water pipe problems, ask the owner of the hardware store, and LoRa for advice from Oulang R&D department)
- Be a wheel, keep iterating, optimize the system in refactoring, and gain experience
- Investigate the needs of customers (family) carefully, pay more attention to customer needs in design, rather than communicate with customers
- When designing a system, it must be assumed that other systems that interact with it are unstable. Let the interaction between systems be like gentlemen intersect, like water. Thereby improving the margin of the whole system.
- Continuous operation and maintenance. For example, it happened before the three rounds of development. My mother touched a human sensor while cleaning, causing the entire light control system to be disordered. At that time, I was in Suzhou connected to the server at home via remote ssh, kicked the broken sensor out of the control system and solved the problem. Therefore, you must allow yourself to be connected to the system for operation and maintenance at any time. The future operation and maintenance must be fully considered in the design.
Freshman summer vacation, I began to try to use WiFiduino to control some objects at home, and realized the control of (broken) solar water (through solenoid valve) (modified the original home pipes and added solenoid valves. I went to the hardware store many times. , I have gained a lot of knowledge and practical experience on water pipes. Later, I will also be useful to do surf pumps.) and control the corridor lights (through photocouplers). I found an abandoned IBM laptop of my dad 10 years ago, installed it with win server 2008, and configured the mysql database, and regularly used http to collect data from the microcontroller. I wrote a simple web interface in php to display relevant information and implement web control. Since the home is assigned a large NAT intranet IP allocated by China Mobile, frp is used to achieve intranet penetration, so that the outside world can access the web pages on the home server.
During the sophomore winter vacation, the previous firmware was improved, wifiduino was used to control the lights in the kitchen, living room, and dining room one after another, and a series of sensors were deployed and connected to the network. Because the WiFi signal of the single-chip microcomputer of the solar energy pipeline was weak, a router was used nearby to bridge. It is worth mentioning that on the night of New Year’s Eve, I was still at home with a power outage 2 minutes before the start of the Spring Festival Gala. I don’t know how my parents feel. .
Sophomore summer vacation, based on the experience of this semester, reconstruct the system. On the server, the reinstallation system provides UI and other services for Centos7 to use the home assistant open source project, using mqtt as the communication protocol. Use nodeJS to write the control logic of light control automation and solar water adding. In the single chip microcomputer, the firmware is updated, and the ota remote firmware update is supported (referring to some Wiot experience, but more tailored to local conditions). In addition, two new flow meters have been added to fully automate the solar water addition (previously, the water addition time was set through the web page). Due to the weak WiFi signal of the flowmeter, we used Arduino uno + LoRa as the communication means. This design, combined with the opinions of parents, fully considered the stability of the overall system. For example, how to handle various types of errors and loss of connection, how to restart after a power failure, how to ensure that the MCU is not disordered when the server is unresponsive, and how to physically switch back to manual after the system is out of control (such as lights, and Solar energy plus water).
In the summer vacation of the junior year, based on the sensor data accumulated in the past, the LSTM model is used to train the neural network through keras+tensorflow to realize the prediction of the light control state. The optimization is still ongoing and is expected to be completed before September. In addition, there are plans to connect to the Tmall Wizard (still in the queue, waiting for the development of the ushio oauth system, the ushio oauth system needs to wait for the development of the ushio user system, and the ushio user system needs stable js-session as support, js-session Need to use fp to accurately identify user equipment.. Currently fp is still in the third test stage. So, let’s do it step by step,,).
Use Arduino UNO as the calculation unit. On the one hand, Arduino Uno has high reliability. My previous smart curtain system used Arduino Uno as the main control board, and it ran smoothly for one and a half years without hardware problems. On the other hand, Arduino Uno has a larger RAM, so there is no need to bother to program the microcontroller in order to compete for RAM.
The main disadvantage of Arduino UNO is its high price, but this cost is necessary to ensure long-term stable operation.
Use ESP-01 as the WiFi communication module. The main reason is that the ESP-01 has been used to build a remote control car in the previous school courses, and I have a better understanding of its working methods and performance to reduce development costs.
Use Anxinke LORA RA-02 LORA as the communication module between LoRa node and LoRa gateway. The reason is that this module is used in the surf project, so I understand it better.
As the most important interface for human-computer interaction in this IoT system, smart speakers play a pivotal role. After research, I use Tmall Elf Sugar R as a home smart speaker. On the one hand, the price/performance ratio of Tmall Genie is very cheap. Second, unlike Xiaomi’s development of Xiao Ai, the purpose of Ali’s development of Tmall Genie is to provide a platform that allows developers to access its network in various forms, which is very important to me.
Initial idea: one-way control + reset device.
Actual realization: The original single-opening is transformed into double-opening, one is connected in series with the relay, and the other is connected with two pin ports.
Two communication modes of WiFi+LoRa are adopted. In scenarios that require high-speed and high-quality communication, such as Tmall Genie, mobile phones, and notebooks, use WiFi as a means of communication. In places where the WiFi signal is unstable, use LoRa for communication. Use MQTT as the application layer protocol.
Use the python3 open source project Home Assistant as the basis to build the main control system of this project. The effect is as follows:
Multimedia is mainly provided by Tmall Genie. In addition, through the Xiaomi box, the video, pictures, and music in the home network disk can be played on the TV and stereo.
dns.yimian.xyz provides dns resolution service.
By mounting the idle 500G mechanical hard disk removed from the old computer to the old IBM server, the storage system is built.
In the local area network, since the home is a win system, smb is used as a sharing protocol to realize file transfer and supports mounting in the local area network. The speed is stable, and the whole network reads and writes about 10MB/s. Access to the external network is realized through http and frp reverse generation, but the speed is slow.
The following is a screenshot of the web interface:
- Full-stack IoT (cloud + pipe + terminal) system construction operation and maintenance experience
- LoRa, WiFi communication system construction experience
- Machine learning development operation and maintenance experience
- Customer needs analysis experience
- Experience in home circuit modification
- Experience in renovation of household water pipes
- How to ensure that all MCUs have high-quality network connections
- The family hopes to reserve a way to return to the oldest manual switch state with one click when the system crashes.
- Control the light switch accurately
- How to reduce the coupling between modules
- Use WiFi, LoRa dual protocol. WiFi is used to connect the single-chip microcomputer closer to the router, and LoRa connects to the single-chip microcomputer in the original place where the WiFi signal is weaker.
- I have equipped each switch with double insurance, so that each switch can be returned to manual state after easy operation. If you want to return to manual mode, just scan the QR code on the switch and follow the instructions. For details, see Emergency Operation Guide
- In the first round of development, the light control is determined by the microcontroller. There is no essential difference with the sound-controlled lights in the corridor, they are all sensors -> single chip microcomputer -> lights. In the second round of development, this judgment logic was transferred to the server. In the third round of development, we introduced night mode, day mode, midnight mode, etc., and used mathematical models in the decision-making process to determine the probability of people using the data of each sensor to determine the control of the lights. However, this method is not always timely. Family members always need to press the toggle switch when it is just dark. Therefore, in the fourth round of development, I hope to use machine learning to let myself learn the switching habits of my family. Currently, data is being continuously collected and trained, and the night accuracy is around 0.75.
- Each module and the single-chip microcomputer use mqtt to interact. Each microcontroller has an online mode and an offline mode. The light control decision module and the solar control module are two separate nodeJS modules, guarded by pm2. In order to ensure uninterrupted services, they use redis (configured persistence) as real-time data storage.
Based on the previously accumulated human sensor data, the LSTM model is used to train the neural network using keras to realize the prediction of the light state.
Self-built OAuth server has realized the access of Tmall Wizard.