NI WSN measurement nodes use an event-based execution framework that you can extend with LabVIEW WSN to customize a node's behavior. The framework is designed to optimize battery life by putting the node to sleep until events need to be handled (nodes configured as routers do not sleep). The diagram in Figure 1 shows the relationship between execution states and the events that trigger their execution. Events that occur during the execution of another state are handled immediately following the completion of the current state.
Figure 1. This diagram represents the LabVIEW WSN execution model, including execution states and transition logic.
Each state in Figure 1, that is programmable with LabVIEW, is represented in a case structure in the LabVIEW WSN template VI. To customize the behavior of any NI WSN node, simply add LabVIEW or C code to the appropriate case, like shown in Figure 2.
Figure 2. Customize the behavior of any NI WSN node by adding LabVIEW or C code to the appropriate case.
Start is called once when the node powers up before the node establishes a connection with the gateway and joins the network. In the Start case, the sending of data, debug, or user messages will fail, because the node is not yet connected to the network.
In the Start case, common operations include the following:
- Setting the sample interval
- Configuring I/O (thermocouple types, voltage ranges, and so on)
- Initializing programming structures
Example 1. Configure the sample interval for 2 S/s and analog input 0 for a voltage range of -10 to +10 V.
Figure 3. Configuring the Sample Interval with the Config Node in a WSN VI
Sample, generally the primary execution state, is called when the Sample Interval timer expires. Configure the Sample Interval with the Config Node in a WSN VI, as shown in the Start example in Figure 3, or from the node's property page in the LabVIEW Project.
In the Sample case, common operations include:
- Reading and writing I/O
- Sending data using radio channels and network shared variables
- Performing threshold, deadband, or averaging logic to conserve power by transmitting less often
- Changing the node's sample rate if battery voltage reaches critical levels
- Interfacing with sensor by converting raw data into engineering units
Example 2. Acquire the voltage on channel 0 and transmit the data only if it exceeds 5.5 V. Otherwise, conserve power by not transmitting. In this example we are utilizing the I/O Variables available to the user.
Figure 4. Acquiring the Voltage on Channel 0 and Transmitting the Data If It Exceeds 5.5 V
DIO Notification is called when a value change event occurs on a digital line that is configured with the Generate Notifications property. You can generate events on rising or falling edges. When a digital value change event occurs, the DIO Notification case is queued to run. Subsequent value change events that occur before the case begins to run are ignored.
In the DIO Notification case, common operations include the following:
- Event counting
- Waking up to handle and respond to an event
Example 3. Use the Generate Notifications property to configure DIO channel 0 to generate events on rising edges. In most cases, this code is placed in the Start case.
Figure 5. Using the Generate Notifications Property to Configure DIO Channel 0 to Generate Events on Rising Edges
Network Status Change
Network Status Change is called when the node establishes or loses connection with the gateway.
In the Network Status Change case, common operations include the following:
- Notifying the host that a connection is established (upon connection)
- Changing the behavior of a node until a connection is re-established
Example 4. Notify the host that a connection to the network has been established.
Figure 6. Notifying the Host that a Connection to the Network Has Been Established
Receive is called when a user message is received. User messages are sent from the host and stored on the gateway. The gateway delivers a message to the node during the next radio activity that occurs with the node. This includes data transmission, or the heartbeat, which is described below. Sending user messages to a node is not guaranteed to be lossless (refer to the Communication and Debugging Methods section for more details).
In the Receive case, common operations include the following:
- Receiving and parsing commands
- Updating parameter values
- Transmitting requested information
Example 5. Receive a sample rate interval value, convert the message to a number, and update the Sample Interval property.
Figure 7. Receiving a Sample Rate Interval Value and Updating the Sample Interval Property
Heartbeat – When the heartbeat timer expires, a node briefly powers up the radio to send a heartbeat to the gateway to maintain the network connection. The timer is reset when any radio transmission occurs.