Introduction
Environmental monitoring is an important application field of wireless sensor networks. In order to collect environmental data in a certain area, sensor nodes need to work in harsh environmental conditions for a long time without human supervision. The software design of sensor nodes provides an important guarantee for the normal operation of nodes.
1 Wireless sensor network system structure
The entire sensor network is composed of several acquisition nodes, 1 aggregation node, 1 data transfer device and 1 host computer for user viewing and control. The system structure is shown in Figure 1. The acquisition node is used for environmental data collection, data preprocessing, and data routing; the aggregation node is responsible for the opening and maintenance of the entire network, sending commands to the acquisition node, collecting node data and serial communication with the data transfer device; the data transfer device is responsible for data transfer and forwarding commands from the host computer; the host computer is the terminal device for data collection, and can set the node collection time interval, sleep time interval, and sensor switch according to user needs.
2 Node hardware circuit
To facilitate data collection, the hardware circuit design of the aggregation node and the acquisition node is the same, but the software design is different. Any node can be used as a sink node and communicate with the data transfer device through the serial port to collect data from other nodes in the network. The hardware structure of the node is shown in Figure 2.
The core chip selected in this design is the ZigBee chip
CC2430
launched by TI. It uses the 8051 microprocessor as the core, and its own RF transceiver is used to realize the communication of wireless sensor network nodes, and provides 4 I/O ports to control the opening and closing of the sensor. The sensor converts the corresponding environmental data into voltage, current and other signals and sends them to the signal conditioning circuit. After relevant conditioning, it is sent to the ADC interface of CC2430 for A/D sampling. Finally, CC2430 stores the obtained A/D value in an external 64 Kb memory. When the node is used as a sink node in the network, the 2 I/O ports of CC2430 are set to UART0 serial port Tx and Rx for serial communication with the data transfer device. For the energy supply part, in order to ensure the long-term stable operation of the node, a 2300 mA nickel-metal hydride rechargeable battery is selected, and two groups of nickel-metal hydride batteries adopt a dual power supply mode. The software controls the switching of the two groups of nickel-metal hydride batteries to realize the rotation of power supply to the node, and controls the solar panel to charge it when the battery voltage is insufficient.
3 Node software design
3.1 Introduction to Z-Stack protocol stack
This software design is based on TI's Z-Stack 2006 protocol stack. Z-Stack 2006 is a ZigBee protocol stack designed by TI for CC2430 chip. It is managed by a simple single-threaded operating system. The operating system is based on the task scheduling mechanism. Tasks are added to the task list according to priority through the API function osalTaskAdd(). Task event triggering realizes task scheduling. Each task can define up to 16 events, and each event corresponds to a unique event number. NextActiveTask() is a task event query function, which returns the event status ActiveTask of the task, and calls the corresponding task processing function ActiveTask() for processing according to the returned event value. The operating system task scheduling is shown in Figure 3.
After completing the node-related initialization, the main function will enter an infinite loop process, which will always detect whether there are events to be processed in the task list of the operating system.
3.2 Node workflow
For the convenience of management and scheduling, the functions to be implemented by the node are defined as events for processing. Each event completes the corresponding function. By connecting the events in a certain relationship, the system functions to be completed when the node is working can be realized. The workflow of the acquisition node and the aggregation node is shown in Figure 4 and Figure 5.
The aggregation node and the acquisition node wake up at the same time. When the aggregation node successfully creates the network and the acquisition node successfully joins the network, all the nodes in the network are in communication state. The aggregation node will send a message indicating that the network is ready to the data transfer device through the serial port. After receiving the message, the data transfer device decides whether to upload data and what data to upload according to the requirements of the upper computer. After receiving the command, the aggregation node will trigger the corresponding event for processing, first commanding the acquisition node to upload the corresponding data to it, and then sending the data to the data transfer device by triggering the serial port event. After successfully joining the network, the acquisition node is also in a ready state, waiting to receive the command of the aggregation node and perform the corresponding event triggering processing.
Before each communication ends, the aggregation node will send a sleep request message to the data transfer device. After receiving the message, the data transfer device will set the sleep process of all network nodes according to the requirements of the host computer.
3.3 Serial communication protocol
The communication between the aggregation node and the data transfer device is carried out through the serial port. The serial communication protocol ensures the safe transmission and reception of data, which is convenient for the aggregation node and the data transfer device to parse and store the data. The data frame format of the serial communication between the data transfer device and the aggregation node is as follows:
Among them, SOP is the start identifier, and 1 byte is used to indicate the start of the data packet. This byte is defined as 0x02; CMD represents the command ID, and 1 byte of data is used to identify the command message. LEN represents the length of DATA, and 1 byte is used to indicate the length of the data in the DATA bit. DATA is the specific data to be sent. FCS is the check bit, and XOR (exclusive or check) is used here to check all the data in CMD, LEN, and DATA.
When the aggregation node and the data transfer device receive data through the serial port, they parse the data by judging CMD. There are several types of CMD for serial port data:
①0x03, the data transfer device sends a command to upload the routing table. In response, the CMD identifier of the aggregation node uploading the routing table data through the serial port is 0x83.
②0x04, the data transfer device sends a command to upload the neighbor table. In response, the CMD identifier of the aggregation node uploading the neighbor table data through the serial port is 0x84.
③0x05, the data transfer device sends a command to upload the collected data. In response, the CMD identifier of the aggregation node uploading the collected data through the serial port is 0x85.
④0x89, the aggregation node sends to the data transfer device, indicating that the network is successfully created and waiting for command messages. ⑤0xF9
, the aggregation node sends to the data transfer device, indicating that all data has been uploaded and waiting for sleep. In response, the data transfer device sends a sleep setting command with CMD 0x09 to the aggregation node through the serial port.
LEN indicates the length of the data, which facilitates the data transfer device to allocate space and store the received data. FCS is a check bit, which is used to characterize the accuracy of the data.
When the aggregation node receives serial port data, it triggers the serial port event of its own application layer to parse the command message sent, and then triggers the corresponding event for processing according to the command.
3.4 Sleep setting
Experiments have confirmed that the node is disconnected from the network during the sleep process. Therefore, in order to save the power consumption caused by the frequent networking of nodes and ensure the synchronization of the working status of all nodes in the network, the software is designed so that the node only performs communication tasks after the network is successfully connected, and only performs collection tasks during the sleep process. When the node collection time arrives, the collection event is triggered, the sensor switch is turned on to collect environmental data, and the I/O port is controlled to perform A/D sampling on the signal collected by the sensor, and finally the sampled value is stored in the external memory in SPI mode. Before each communication ends, the node will determine whether there is a sleep setting command. If a sleep setting command is received, the node will sleep according to the setting until the next wake-up; if no command is received, the node will sleep according to the last sleep setting.
The data frame format of the sleep setting command sent by the data transferor to the aggregation node through the serial port is listed in Table 1.
Sleeping_Time indicates the time when the node is going to sleep; Collecting_Time indicates the collection time interval of the node during the sleep process; Current_Time is the current calibration time; Sensor_Flag indicates the sensor switch flag. When the collection time is reached during the sleep process, environmental data is collected, sampled and stored. The current calibration time is sent to the collection node to ensure the accuracy of the node collection time and time synchronization. At the same time, the switch flag of the sensor can control which sensors are turned on or off to collect environmental data of interest to the user. When the sleep time is reached, the node wakes up and connects to the network.
3.5 Charging
In order to ensure that the nickel-hydrogen battery can power the node for a long time, the node hardware circuit is designed with a charging control circuit to manage its charging.
CC2430
specifically provides an I/O port for A/D sampling of the power supply voltage. When the power supply voltage is insufficient (that is, lower than the set value), the software will switch to another group of power supplies to power the node first, and then turn on the solar charging circuit to charge the power supply. The node consumes a lot of power when communicating and collecting data. Therefore, after each communication and data collection, the node will detect the current power supply voltage value and the current charging voltage value. According to the two voltage values, it will decide whether to switch the power supply, whether to supply power, and whether charging is completed.
3.6 Exception handling
Nodes in the network may have some exceptions when working, so these exceptions must be corrected to ensure the normal operation of the node.
(1) Asynchronousness of newly added nodes
When all nodes in the network are in sleep mode, if a new node joins the network, in order to ensure that its network status is synchronized with other nodes, the newly added node will sleep according to the default sleep setting when it cannot find the network. After waking up from sleep, it will continue to search the network. This cycle will continue until the network is found.
(2) Data error
The data obtained by the data transfer device through the serial port must be verified. If the verification fails, the data packet will be discarded and the aggregation node will be ordered to resend the data.
(3) No response
The aggregation node sends a request command to upload data to a certain collection node. If the node does not respond within the specified time, the aggregation node will assume that the node is abandoned and it will send a request to upload data to the next node.
(4) No confirmation
After receiving the data from the collection node, the aggregation node will send a confirmation message to the node, indicating that the data has been received. The collection node will decide whether to resend the data based on whether it has received the confirmation message.
Conclusion
The software design of the wireless sensor network node largely determines the stability and durability of the entire system. The task scheduling mechanism and exception handling determine that the system is in a stable state when working, and the node's charging management system ensures the energy supply for the node to work for a long time. The system can collect large amounts of data accurately in the field according to user needs. This design can be used to monitor the environmental information of a certain area for a long time without human supervision, and has broad application prospects.
Previous article:nesC embedded programming language in wireless sensor networks
Next article:Using Piezo Film Sensors as Accelerometers
- Popular Resources
- Popular amplifiers
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- CGD and Qorvo to jointly revolutionize motor control solutions
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Nidec Intelligent Motion is the first to launch an electric clutch ECU for two-wheeled vehicles
- Bosch and Tsinghua University renew cooperation agreement on artificial intelligence research to jointly promote the development of artificial intelligence in the industrial field
- GigaDevice unveils new MCU products, deeply unlocking industrial application scenarios with diversified products and solutions
- Advantech: Investing in Edge AI Innovation to Drive an Intelligent Future
- CGD and QORVO will revolutionize motor control solutions
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- I don't understand this speed, is it normal? The environment is esp8266
- [Old Post] Richengfeng's Eighteen Dragon Subduing Palms in C Language
- The "367" of RFID system
- Today at 10:00 AM, live broadcast with prizes: ST's PLC solutions in industrial automation
- MOS tube G pole protection problem
- Understanding Output Voltage Ripple and Noise Part 2: Sources and Suppression of High-Frequency Noise Components
- Interface Board
- Crystal-less BAW Multi-protocol 2.4GHz Wireless MCU
- Sugar Glider Part ⑥ Hardware Design of the Exercise Reward System for Sugar Glider Based on RSL10
- [Technical Discussion] Is it necessary to bring a laptop when testing the distance of a wireless communication module?