Software design of wireless sensor network nodes for environmental monitoring

Publisher:创新脑细胞Latest update time:2011-05-03 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.
























Reference address:Software design of wireless sensor network nodes for environmental monitoring

Previous article:nesC embedded programming language in wireless sensor networks
Next article:Using Piezo Film Sensors as Accelerometers

Latest Industrial Control Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号