"Smart home", also known as intelligent residence, uses advanced computer technology, embedded system technology, network communication technology and sensor technology to organically combine various devices in the home, optimize users' lifestyles, facilitate users to manage devices, and enable linkage between multiple devices through scene settings.
In the hierarchical structure of the home network, the entire system is divided into 5 layers:
The physical media layer (Media), the underlying protocol layer (Protocol), the application program interface layer (API), the application program layer (APP) and the final user interface layer (UI). The first and second layer standards have been promulgated and applied in practice; the third layer (API) is the key to the development of home network technology and is a hot topic in the current industry research; the fourth layer is the application layer, which is a variety of applications developed by technicians based on the third layer; the fifth layer is a variety of user interface (UI) tools, including various remote control devices, emergency switches, help buttons and other visual interface devices, which are crucial to the performance and use of the entire system. This article mainly focuses on the third and fourth layer structures and designs data communication protocols that meet the smart home system platform.
1 System Overall Plan
1.1 Overall design plan
In Figure 1, the ARM main controller acts as a remote Web server for smart homes. It receives remote control data packets through the Ethernet chip ENC28J60, sends control commands through the RF module after completing data parsing, delays and receives node response data, and sends the response data in json data format (a data storage format) through the gateway to locally update Web information, thereby achieving the effect of monitoring and controlling the home environment.
Figure 1 Smart home remote monitoring solution
1.2 Control Unit
The control unit uses ARM microcontroller STM32F103RBT6, Cortex-M3 core, 64-pin LQFP package. It has 128K bytes of program storage space, 20K bytes of RAM, a maximum operating clock of 72MHz, rich on-chip resources, a 7-channel DMA controller, and can support SPI, USART and other peripherals. It is suitable for the development and design of low-cost, low-power embedded systems.
In Figure 2, the chip is connected to 3 peripherals through the SPI serial port: SD card interface, Ethernet chip ENC28J60 and RF module chip nRF24l01. The PA4-PA7 ports of the ARM microcontroller are used as the chip select signal, clock signal pin, MISO and MOSI ports of the SD card respectively; PB12-PB15 are used as the chip select signal, clock signal pin, MISO and MOSI ports of the Ethernet chip ENC28J60 respectively; PC6 is the RF module RX/TX mode enable terminal, PC7 is the SPI enable pin, PC10-PC12 are used as the MOSI, MISO and clock signal pins of the RF module nRF24L01 respectively. Combined with the microcontroller application capabilities of the MCS-51 microcontroller, a simple and practical embedded smart home gateway and terminal control solution is designed.
Figure 2 System control unit design. [page]
1.3 RF communication unit
The receiving part uses the wireless RF module nRF24l01, which is used in the 2.4GHz global open ISM band; the maximum working rate is 2Mbps, efficient GFSK modulation, and strong anti-interference ability; there are 126 channels in total to meet the needs of multi-point communication and frequency hopping communication; built-in hardware CRC error correction and point-to-multipoint communication address control [9]. At least two modules form the communication system. In Figure 3, one is the main controller data transmitter; the other is the node device data receiver. The receiving end completes the command data reception and links the corresponding device according to the command content; after completing the command, the node RF module enters the sending state and returns the current node device state.
Figure 3 Wireless communication system.
2 Software Design
2.1 RF working mode selection
The nRF24101 RF module has three transceiver modes: EnhancedShockBurstTM transceiver mode, ShockBurstTM transceiver mode and direct transceiver mode. The EnhancedShockBurstTM transceiver mode is determined by the device EN_AA register configuration content.
In Enhanced ShockBurst TM transceiver mode, the chip uses the first-in first-out stack area, data is sent from the microcontroller at a low speed, and transmitted at a high speed, the rate is 1Mbps. Through this energy-saving method, even if a low-speed microcontroller is used, a high RF transmission rate can be obtained. And all high-speed signal processing related to the RF protocol is performed on the chip, which has three major advantages: energy saving; low system cost; short data air residence time, high anti-interference. At the same time, it also reduces the average operating current of the entire system.
2.2 Data sending and receiving process
2.2.1 Main controller firing process
The wireless communication system designed in this paper is under the same channel. In the initial state, there is only one transmitting node and multiple receiving nodes. The main controller RF process is shown in Figure 4.
(1) Waiting for the arrival of network data packets, the nRF24101 RF module starts the transmission mode and sends it by broadcasting on the configured channel with a delay of 50ms to ensure that each slave controller can receive the data packet.
(2) After the data transmission is completed, the RF module is immediately configured to receive mode, receives the status data frame from the slave controller device, and times for 2 seconds. If it times out or successfully receives the response data from the slave controller device, it will automatically reconfigure to send mode and return to step 1 to prevent all RF modules from entering the receive mode and causing an interlocked "pseudo-death" state.
(3) If the response data from the controller device is successfully received, the RF module enters the waiting state.
2.2.2 RF flow from controller
All receiving nodes receive the data packet and parse and check the driver interface data of the data packet, such as receiving address matching, command code, operation file? If there is a matching node, it will enter the driver application and execute the operation. The RF module is in receiving mode in most cases. The specific process is shown in Figure 4:
Figure 4 Master control RF process
(1) The slave controller node nRF24101 RF module is configured in receive mode until a data packet is received.
(2) Parse the driver interface part of the data packet to see if the receiving address matches. If not, return to step (1) and then determine the command opcode and file flag. If an illegal opcode or file flag appears, return to step (1). If there is a corresponding driver interface, enter the driver application.
(3) According to the input application data (record control data and record data), the operating device writes the device status into the transmission data frame. After completion, the RF module is configured to enter the transmission mode, and the transmission data frame is returned to the main controller with a delay of 1 second.
(4) Determine whether the transmission is successful. If it fails, re-enter step (1). If it succeeds, end and enter the initialization state.
Fig. 5 Slave node RF flow chart.
[page]
Wireless communication protocol
There are many types of smart home terminal devices with different functions. To control different devices in a unified way, it is necessary to abstract various devices and extract their common features. The terminal device can be abstracted into a file, and a piece of memory is allocated on the control end to describe the current state of the device. The device control method is used to read or modify the current state. The control method can be divided into three categories: file reading (Read), file modification (Write), and file control (Control).
Read: read device file operation, that is, scan and query the node device status. The programming API is as follows:
void drv_lit_read(rxp_cmdreq req)The above is the API entry for reading the device. The parameter req is a structure pointer. The operations for writing and controlling the device are similar.
Write: Write device file operation, that is, modify the node device status. The programming API is as follows:
void drv_lit_write(rxp_cmdreq req)Control: Control device file operation, that is, adjust the node device status. The programming API is as follows:
void drv_lit_cnt(rxp_cmdreq req)Not all files support these three control methods. Most files only support the first two control methods. The following takes the light control device as an example.
3.1 Communication Protocol
The maximum data payload of the wireless RF module nRF24l01 corresponding to the transceiver mode is 32 bytes. The data packet is a frame of data, which can be divided into three types of data: driver interface data, record control data and record data. The input frame and output frame data types are the same. The data format is shown in Table 1.
Table 1 Frame data format
(1) Driver interface data.
Dest: receiving end address, 1 byte, attribute value ranges from 0-255, can represent 256 node addresses, meet the node resources of most smart homes.
Src: sender address, 1 byte, same meaning as Dest.
Cmdid: node command code, 1 byte, as shown above, there are three types: 0x01, indicating a read command (read); 0x02, indicating a write command (write); 0x03, indicating a control command (control).
The node corresponds to the slave controller number.
Fileid: File identifier, 1 byte, that is, the device number corresponding to the node address, supporting up to 256 files from 0x00 to 0xFF.
(2) Record control data.
Result: Operation result code, 1 byte, required to fill in this byte when data is returned. 0x00, operation successful; 0x10, illegal node; 0x11, illegal file identifier; 0x12, illegal initial record value; 0x13, illegal record. 0xFF, default invalid value.
Start: Record start value, 1 byte represents. When there are multiple record operations, this value is the corresponding record sequence.
Len: record length, 1 byte. When used as input data, it indicates the length of the record operation. If the Len value is greater than the maximum record length of the current node, the maximum value of the current node record length is taken. When used as output data, it indicates the record length of the current node operation.
(3) Records: Record data buffer, the buffer is up to 25 bytes.
The buffer can store multiple records. The record format is shown in Table 2. The byte length of each record varies, usually around 3-5 bytes, and a maximum of 8 records can be stored.
Table 2 Recording data format
The Len value has a different meaning from the Len value in the record control data. It indicates the byte length of the record, which does not include the byte length itself, and is 1 byte long. The Opt value is a reserved byte, which is generally meaningless. The control command is related to this byte, and is 1 byte long. Content is the record value of the device file. The record byte length is uncertain, and is generally 1-2 bytes long.
3.2 Protocol extension and features
Address resources, single-byte Dest and Src address allocation can fully meet the requirements of ordinary smart home users. For users with complex home environments and more address allocation points, there may be insufficient resources. In this case, the Dest and Src addresses can be expanded to 16 bits, that is, 2 bytes. Meet the requirements of 65535 nodes.
Node command code, three types of commands only occupy two bits of Cmdid, and the remaining six high bits are reserved for protocol expansion.
Record options, Opt is a reserved byte, the default value is 0x00, this byte is mainly for control operations, used to record control operators, as shown in Table 2, mainly for the brightening and dimming operations of the light control file.
The design of this communication protocol has the following main features:
(1) Unify peripherals, abstract external devices into standard files, and record the file contents in the controller memory. To operate a specified device, you only need to access the memory space data where the device mapping file is located, standardize peripheral standards, and improve communication efficiency.
(2) The formulation of the communication protocol greatly optimizes the data transmission performance between the main controller and the RF module. The main controller only needs to fill in the fixed communication protocol format, simplifying its processing process.
(3) The data processing process from the control node is also simplified.
[page]
Communication protocol implementation resultsAccording to the system functional requirements, it can be divided into intelligent temperature control, intelligent security control, intelligent home appliance control, intelligent lighting control, etc.
Intelligent temperature control: The system collects indoor temperature in real time and displays it to the user in a graphical form. The user can control the indoor temperature as needed.
Intelligent security control: The system integrates anti-theft and anti-robbery functions, can remotely monitor home conditions through the web page, and can query the status of the control alarm.
Intelligent lighting control: Users can control the lighting effects of their homes according to their needs. It has a dimming function, which can not only meet the needs of users, but also achieve energy saving and environmental protection. The recorded data description is shown in Table 3.
Table 3 Lighting control record data
The first byte of the recorded data, Len, indicates the current recorded byte length. The three lighting control methods are described as follows:
Read: Read the current light brightness.
Input: None.
Output: Opt reserved byte 0x00.Value represents the brightness value of the current light (0x00-0x09). The larger the value, the higher the brightness. The same below.
Write: Set the brightness value of the light.
Input: Opt reserved byte 0x00. Value is the brightness value to be set.
Output: Opt reserved byte 0x00.Value represents the current light brightness value (0x00-0x09).
Cnt: Adjust the brightness of the light.
Input: The lowest bit of Opt is 1, which means to reduce the brightness; the lowest bit of Opt is 0, which means to increase the brightness. It is meaningless if Value is omitted.
Output: Opt is the reserved byte 0x00. Value represents the current light brightness value (0x00-0x09).
The lighting control device supports reading and returning multiple records at the same time. The read operation of the device has no record input, but has record output; the write operation and control operation have record input and record output. Assume that the current operation node is 0x00, the master control node is 0xFF, and the Value value is 0x03.
Take the lighting control command as an example:
Control command (0x03): Assuming the current brightness value is 0x03, add 1 to the light brightness value. The input data frame is as shown in Table 4, and the output data frame is as shown in Table 5.
Table 4 Input data frame
Table 5 Output data frame
When the input data frame and the output data frame are converted to each other, the sending subject is different, so the sending address and the receiving address are swapped. Since it is a control command, Cmdid is set to 0x03. If it is a read command or a write command, the byte is set to 0x01 or 0x02. From the above, it is known that the current operation node is 0x00, which is the setting value of Fileid. Result indicates the data return result code, and 0x00 indicates that the operation is successful. It is meaningless in the input data frame.
In this example, there is only one record value, so the data input and output frame record address Start starts from 0x00, and the data frame length Len is 0x01.
The data frames of read commands and write commands are similar, refer to the control command format.
5 Conclusion
In this system, the embedded Web server is used as the architecture to realize the remote monitoring and control of the smart home terminal equipment, and the communication protocol design for the low-cost smart home is finally completed based on the 32-byte data frame of the nRF24L01 radio frequency module. In the actual operation process, it can also be adjusted and controlled through the web page, and finally the terminal file device can be controlled, and the functions of switching, brightening, and dimming of the lighting control equipment can be realized. It can return accurate data information within 1 second after issuing the command, ensuring the real-time control of the system, and has high application value.
Previous article:Development of vehicle driving recorder based on ARM and CAN bus
Next article:How to make home appliances safer with low-cost ARM Cortex-M microcontrollers
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- Xsens Sirius Series Inertial Sensors Enable 3D Inertial Navigation in Harsh Environments
- Infineon's Automotive Landscape: From Hardware to Systems
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Some basic knowledge of SPI-Flash
- Absorption characteristics of oxygenated hemoglobin (HbO2) and deoxygenated hemoglobin (Hb) to red light RED and infrared light IR
- Openmv4 for sale
- KTY84 Temperature Sensor
- 【NXP Rapid IoT Review】- Unboxing and Demo Experience
- Master Verilog HDL: IC Design Core...
- How much driving time is required for transistors and MOS?
- The PCB drawing is initially drawn, but I am a novice and don't understand my own problem. I hope to get your advice and help
- A big mistake
- PIFA and MONOPOLES Antenna Design Considerations