Smart test
Design of ZigBee and 3G Remote Wireless Metering System
Designed a remote wireless photometry system based on the combination of ZigBee short-range wireless communication technology and 3G long-range wireless communication technology; the processor of this system is Samsung S5PV210 processor, and the short-range wireless communication module uses TI’s CC2530 chip, 3G The network card device uses the ZTE MF190 wireless network module. The specific software and hardware design scheme of the system is given in the article. The results show that the system can achieve stable and efficient monitoring effects, and has good practicability and application value.
1 Overall system design
ZigBee technology is a wireless communication technology with low speed, close range, low power consumption, low complexity, low cost, reliable communication and large network capacity. According to the IEEE 802.15.4 protocol standard, the working frequency band of ZigBee is divided into 3 frequency bands: 868 MHz, 915 MHz and 2.4 GHz. The 2.4 GHz frequency band is divided into 16 channels. This frequency band is a general industrial, scientific, and medical frequency band. The frequency band is a free and application-free radio frequency band. In this frequency band, the data transmission rate is 250 Kb/s, and the power consumption emission output is only 0~3.6 dBm. The 2.4 GHz frequency band is selected for comprehensive consideration.
The system is mainly composed of three parts: illuminance terminal collection node, coordinator master node and host computer server monitoring center. The overall structure of the system is shown in Figure 1.
Figure 1 Overall structure of the system
2 System hardware design
The ZigBee wireless transmission network of this system is composed of 4 terminal collection nodes with light intensity sensors and 1 coordinator master node. The terminal collects the light intensity data collected by the BH1750 digital illuminance sensor through the CC2530 radio frequency transceiver module to wirelessly send to the coordinator master node CC2530 radio frequency transceiver module, and the master node CC2530 radio frequency transceiver module communicates with the main controller S5PV210 through the 3G network The data is transmitted to the remote host computer server monitoring center.
2.1 Coordinator master node design
The main role of the coordinator master node in the entire ZigBee wireless network is to establish, maintain, and control the joining of terminal nodes, as well as data aggregation, buffering and forwarding. It is the control center of the ZigBee network, and its structural block diagram is shown in Figure 2. The wireless radio frequency transceiver chip CC2530 completes networking and wireless data transmission and reception; 3G Internet access completes the long-distance wireless transmission of data; the main control chip S5PV210 is responsible for the coordination and control of the entire main node module.
Figure 2 The block diagram of the main node structure of the LAN control
CC2530 is a true system-on-chip (SoC) solution for IEEE802.15.4, ZigBee and RF4CE applications. It can build powerful network nodes at a very low total material cost. CC2530 combines the excellent performance of RF transceivers with Industry standard enhanced 8051 CPU, in-system programmable flash memory, 8 KB RAM and other powerful functions. CC2530 has 4 different flash memory versions: CC2530F32/64/128/256, with 32/64/128/256 KB flash memory respectively. The short transition time between operating modes can further ensure low energy consumption.
2.2 Terminal collection sub-node design
The terminal collection node is responsible for transmitting the collected light intensity data to the coordinator master node. The schematic diagram of the hardware circuit is shown in Figure 3. The digital light sensor BH1750 is responsible for the collection of light intensity data; the wireless radio frequency transceiver chip CC2530 is responsible for wireless communication with the local area network control center, collecting data and sending the data to the local area network control center.
Figure 3 Schematic diagram of the local area network acquisition node circuit
BH1750 is a digital light intensity sensor integrated circuit used for a two-wire serial bus interface. This integrated circuit can adjust the brightness of the LCD or keyboard backlight according to the collected light intensity data. Its high resolution can be used to adjust the brightness of the LCD or keyboard backlight. Detect a large range of light intensity changes, the detection range can be from 1 to 65 535 lx, supports I2C bus interface (f/s Mode Support), and has spectral sensitivity characteristics close to visual sensitivity (peak sensitivity wavelength is typically 560 nm) [ 6]; Output the digital value of the corresponding brightness; achieve low current through the power reduction function; achieve stable measurement through the 50 Hz/60 Hz elimination of light and noise; support 1.8 V logic input interface; no other external components are required; light source dependence is weak (Incandescent lamp, fluorescent lamp, halogen lamp, white light LED, fluorescent lamp); there are two optional I2C bus slave addresses; the adjustable measurement result has a greater influence on the light entrance size; the error varies within ±20%; affected by infrared The impact is small.
3 Software design
System software design includes terminal node collection program, ZigBee network wireless transmission program, 3G network wireless transmission program and upper computer server monitoring program software design.
3.1 Terminal node collection program design
The communication between BH1750 and the main controller uses the standard I2C bus communication protocol. The I2C bus is a two-wire serial bus developed by NXP, used to connect the microcontroller and its peripheral devices [7]. The main controller sends various control commands to the BH1750 and reads measurement data through the I2C bus interface. The main control commands are as follows: power-on command is 0x01; power-off command is 0x00; continuous H resolution mode is 0x10; continuous L resolution mode is 0x13; H resolution mode is 0x20; L resolution mode is 0x23.
Take "continuous high resolution mode" as an example, the measurement steps are as follows:
① Send the "power on" command.
② Send the "continuous high resolution mode" command.
③ Wait for the completion of the sub-high resolution mode measurement (time is 180 ms).
④ Send the read command.
⑤ Read the measurement result.
3.2 ZigBee network wireless transmission program design
After the ZigBee coordinator node is powered on, the ZDO layer performs a series of initialization work for the first time, and then calls the initialization device function of the ZDO layer, which finally triggers the network initialization function to start building a new network. When establishing a network, the coordinator node first scans each channel one by one, sorts the channels according to the energy value of each channel, and selects the channel whose energy value reaches a certain size as the available channel. Secondly, the network layer selects the channel among the available channels, and randomly selects a 16-bit network identifier (PANID) in the selected channel to assign to this new network [8]. The software design flowchart of the coordinator is shown in Figure 4.
After the terminal collection node is powered on, it initializes the device and then detects whether there is a network around it. When it finds that there is a network, the network layer will give the ZDA layer to find the network feedback information, and then the network layer will send a join to the network with relatively large energy intensity. Network request; if joining the network is successful, the network layer will give feedback to the ZDA layer to join the network. After successfully joining the network, start to send a binding request to the coordinator. After the binding is successful, start to collect the light data, preprocess the collected data and send it wirelessly to the coordinator node. The sensor terminal acquisition node software flowchart is shown in Figure 5.
3.3 3G network wireless transmission part design
3.3.1 Porting of usb_modeswitch
Usb_modeswitch is a tool for converting the working mode of USB devices under Linux system, used to control USB devices containing multiple USB sub-devices. In the Linux environment, manufacturers generally do not provide drivers for USB devices on Linux systems, so you need to use the usb_modeswitch tool to perform mode conversion. The device mode depends on usbstorage and usbserial, so the support of these two modules is required on the development board, and the small device can work in these two modes normally.
Usb_modeswitch relies on a series of library files provided by libusb. First, you need to install libusb. Unzip and enter the libusb1.0.6 directory. Use the following command to create a subdirectory install to store the living library files and header files. The porting process of usb_modeswitch is omitted---Editor's note.
3.3.2 PPPD transplantation
Linux already supports 3G module driver and PPP network protocol stack in the kernel. What needs to be done is to configure 3G module driver and PPP network protocol stack related options in the kernel. The transplantation process of PPPD is abbreviated-editor's note.
Create three files under the /etc/ppp/peers directory of the development board file system, the code is omitted-editor's note.
3.3.3 Design of communication program between master node and host computer
Through PPPD dial-up, the connection of the data link layer can be established. The data link layer adopts the PPP protocol, which is a character-oriented protocol designed for the transmission of data packet connections between two peer entities. The extended link control protocol LCP is used to establish, configure and test data links. The network program also needs the support of TCP/IP protocol, and the Linux kernel has reserved support for TCP/IP and other network protocols. Write the network client application program on embedded Linux and the Windows network server application program to transmit the data you want to transmit. The program flow chart of the communication between the main node main controller and the host computer server is shown in Figure 6.
Figure 6 The main node and the host computer communication program flow chart
3.4 Server host computer monitoring part
The software development of the server host computer adopts the Microsoft Visual C++6.0 development environment and the object-oriented programming method. A corresponding class is established for each window. Objects are created on the basis of classes. The operation of the objects is Operation on the corresponding window. The monitoring center software mainly realizes the following functions: establishing the server and receiving the connection of the client; receiving and displaying the data sent by the client; real-time curve display; historical data query.
4 Debugging test
4.1 System debugging
In the process of system debugging, the data received by the upper computer during data transmission is individually wrong. By checking the binary code, it is found that the characters 0x11 and 0x13 are not received. Narrow the scope to see where the problem lies. The inspection found that the master node controller S5PV210 did not receive the 0x11, 0x13 characters, and the master node CC2530 microcontroller has received the 0x11, 0x13 characters, then the problem must be on the serial port.
In Linux serial programming, c_iflag (termios member variable) is not effectively set, so there is no problem when transmitting ASCII code, but when transmitting binary data, it will be lost when it encounters 0x0d, 0x11 and 0x13. These characters are special characters and are used for special control. Just turn off the ICRNL and IXON options.
The specific method is to add the following statement in the Linux serial port initialization function of the main controller:
Options.c_iflag &= ~(ICRNL | IXON | IXOFF);
Options is the structure of the termios type previously defined. Through the above settings, the special functions of 0x11 and 0x13 characters can be shielded, so that the above characters can be transmitted normally.
4.2 System function test
After connecting the hardware device, configure and compile the kernel, transfer the compiled kernel to the development board via USB, and then restart. Then put the compiled application program to the development board through the serial port terminal. Insert the 3G network card into the USB interface, use the following commands to create 3 TTY device file nodes, the code is omitted-editor's note.
We can see that PING Sina's WEB server can be pinged, indicating that it has successfully connected to the Internet. Then put the 4 terminal sub-nodes in different lighting environments, start the host computer software, establish the server side, and start to wait to receive the connection request from the master node client and the sent data and display it. Start the client program of the main node to connect to the server, and start the collection and transmission program of the sub-nodes. The diagram of the monitoring data received and displayed by the host computer is abbreviated-editor's note.
Conclusion
This article describes a long-range wireless photometry system that combines low-cost, low-power short-range wireless ZigBee technology with long-range 3G mobile communication technology, and completes the software and hardware design of the collection terminal node and the coordinator master node. , Real-time display and analysis of the collected data by writing the upper computer software of the Windows platform.