1 Introduction
With the advancement of technology, people's requirements for communication technology are also growing, and short-range wireless communication technology is also produced.
Nowadays, various short-range wireless communication technologies are emerging one after another. Among them, Bluetooth (Bluetooth), ZigBee, Wi-Fi, WiMAX, Wireless USB and UWB are more successful and widely used.
ZigBee's protocol architecture is based on the IEEE 802.15.4 standard. The IEEE 802.15.4 standard defines the ZigBee physical layer (PHY) and the medium access control layer (MAC); the ZigBee Alliance defines the network layer (ZWK), application layer (APL), and security service specifications for the ZigBee protocol. As an emerging low-rate wireless communication technology, ZigBee technology has low speed, low power consumption, low cost, license-free wireless communication frequency band, short-range communication, short delay, reliable data transmission and diverse networking modes. Technical features that make ZigBee technology suitable for applications such as industrial control, smart home, medical care, smart agriculture, consumer electronics and remote control. At present, the Bluetooth technology is complex, the application system cost is high, the power consumption is high, and the battery power supply life is short. In the case that it cannot break the price bottleneck, ZigBee technology will have a broader application prospect.
In accordance with the requirements of the ZigBee protocol specification, this paper designs a set of indoor lighting automatic control system for smart home network. The system can accurately realize remote control of indoor lighting devices, and can adjust the opening and closing of the electric light by monitoring the change of indoor light, thereby realizing intelligent control of lighting, and also improving the reliability and flexibility of the control system.
2. Structure of indoor lighting automatic control system based on Microchip ZigBee protocol stack
The indoor lighting automatic control system introduced in this paper is a typical application of ZigBee technology in smart home.
The Microchip ZigBee protocol stack is based on the ZigBee wireless protocol specification, but it is not fully compliant with the ZigBee protocol, does not support clustering and peer-to-peer networking, has no security and access control features, no router functionality, and does not support one-to-many binding. . Designing a ZigBee node using the Microchip ZigBee protocol stack requires hardware components that include at least one PIC18F microcontroller with an SPI serial port, an RF transceiver with the required external components, and an antenna that can be formed by leads on the PCB. Antenna or monopole antenna.
The system constructs a star network, a master-slave network consisting of a coordinator node and a number of terminal nodes. The first FFD (full-featured device) that is started is the PAN coordinator and chooses a different identifier than the other PANs in its coverage area as its own PAN identifier. The PAN flag is usually set to 0 when there are no other PANs in its working area. The coordinator can allow other FFDs and RFDs (thin functional devices) to join the network. In a star network, the coordinator node and the terminal node can send or receive data to each other, but direct communication cannot be performed between two terminal nodes. If one terminal node wants to send data to another terminal node, it can only coordinate. This intermediate medium is completed.
According to the development requirements of the Microchip ZigBee protocol stack, we designed an indoor lighting automatic control system that can transplant the Microchip ZigBee protocol stack. The block diagram of the system is shown in Figure 1.
The coordinator node and all terminal nodes together form a ZigBee wireless communication network. The role of the coordinator node is to establish a network and assign network addresses to nodes added to the network. At the same time, it is also responsible for communication through the serial port and the host computer. Each terminal node is to implement the function of the specific switch light, and The results of the work are fed back to the coordinator node. In addition to real-time monitoring of network working conditions, the host computer also functions as a home gateway, which can provide various remote intelligent control interfaces to establish a connection between the ZigBee network inside the home and the Internet, so that users can use one connection. The PC on the Internet controls the electrical equipment in the home.
Figure 1 Schematic diagram of the lighting control system
3. Hardware design of the system node
The design uses Microchip's PIC18LF4620 microcontroller as the controller, and the RF transceiver part uses TI's CC2420 RF module. The controller is connected to the RF module via the SPI bus and some discrete control signals. The controller acts as the SPI master and the RF module acts as the slave. The controller implements the IEEE 802.15.4 MAC layer and the ZigBee protocol layer, and the RF module CC2420 implements the IEEE 802.15.4 physical layer and some MAC layer functions. Figure 2 is a block diagram of the terminal node: Figure 3 is a block diagram of the coordinator node:
Figure 2 Block diagram of the terminal node
Figure 3 Coordinator node structure block diagram
The interface circuit of PIC18LF4620 microcontroller and CC2420 RF module is shown in Figure 4:
Figure 4 PIC microcontroller and RF module interface circuit
The terminal node controller receives the data from the coordinator node through the CC2420 radio frequency module, and completes the relay control according to the instruction of the coordinator node, thereby realizing the transition of each lamp switch state in the room.
The terminal node can monitor the change of the indoor light through the photoresistor. When the brightness of the light exceeds a certain value, the controller will detect the change of the output signal from the photoresistor and inform the coordinator of the change. After the coordinator receives the signal, it repeats the previous operation to complete the switching action of the lamp. This design is suitable for wall corner lights.
The coordinator node sends a control signal through the keys on the keyboard, breaks the relay on the corresponding terminal node to control the light on and off, and feeds the received slave node signal to the master node through the RS232 serial port. The LCD screen is used to display the working status of each terminal node.
4. Software design of system nodes
This involves the concept of an endpoint binding. A ZigBee node can support up to 32 endpoints (numbers 0~31) and 8 interfaces (numbers 0~7). Endpoint 0 is reserved for device configuration, while endpoint 31 is reserved for broadcast only. The remaining 30 endpoints are used for the application. Each endpoint has a total of eight interfaces, so the application can have up to 240 virtual channels in a single physical channel. The coordinator node is responsible for establishing and maintaining a binding table that describes the logical links between the endpoints and uniquely defining a data link through the source endpoint and the cluster ID. In this lighting system, we assign a unique endpoint number in the node to the relays on each terminal node and the buttons on the coordinator, and use this endpoint number to mark these application objects. A connection is established between the relays in the terminal node and the different buttons on the coordinator, and the coordinator node transmits the data packets sent by the respective switch terminals to the corresponding endpoints, thereby implementing the control of the coordinator nodes for the various lights distributed indoors.
4.1 Terminal node software design
The task of the terminal node is mainly to receive data from the coordinator and perform switching operations on the corresponding lights according to the data, and feed back the result of the operation to the coordinator node. After powering up on the terminal node, scan all available channels to find the neighbor coordinator and apply to join the network. Since the battery is powered, it is necessary to ensure the low power consumption of the terminal node. The design uses a timed wake-up method to connect to the server, receive and transmit data, and enter the sleep mode at other times to achieve the lowest power consumption of the terminal node. The program flow chart of the terminal node is shown in Figure 5.
Figure 5 terminal node system flow chart
4.2 Coordinator node software design
As a network coordinator, its functions are mainly divided into two parts, namely, establishing a network and performing network management. The ZigBee Coordinator is primarily responsible for establishing ZigBee networks, assigning network addresses and maintaining binding lists. The coordinator creates a new network by scanning a free channel, maintains a list of networks of currently connected devices, and supports independent scanning procedures to ensure that previously connected devices can rejoin the network.