Flow to Poll a Tag Once for an Event-Driven Poll
Estimated reading time: 3 minutes
Often there is no need to regularly poll a register. Instead, a common use case requires data to be collected only when an event, such as a change of state (on/off), triggers a poll.
**Example Use Case 1**: It likely is not necessary to pay attention to a temperature sensor if the device’s motor is not running. In this example, the temperature sensor only needs to be monitored if there’s a significant change or if another condition warrants monitoring. In cases such as this, a poll once flow should be configured.
**Example Use Case 2**: To minimize cloud IoT storage fees and bandwidth costs, monitor critical processes and capture the data every second. Then, publish collected values only once per minute. If no problems arise, there is no need to send data every second. However, if an issue occurs, then more granular data is required for analysis, so this event will trigger the poll once poll to publish all the once-per-second data collected for the last minute.
Example Use Case 3: A motor for a pump only needs to be polled when the power switch is turned on. In this case, you would want to continuously poll the switch and when its state changes, execute a poll once trigger to poll the motor control.
The poll once device topic for a DeviceHub tag is designed to be used to poll a device register only when triggered by an event. Take the following steps to configure a device register to poll once:
Create Device Tags
Before configuring a flow, device tags must be created to specify registers that will be polled.
- In the OT Link Platform navigation pane, select DeviceHub > Tags.
- Click the icon at the top right of the Tags window.
Configure a tag, similar to the following example.
Poll once tags must have the polling interval set to zero.
For this example, three tags are created:
One of these tags will have a polling interval set to 1 because this will be used to continuously poll a device topic, waiting for a state change.
The other tags will be used as poll once triggers that respond to events (state changes).
In the DeviceHub > Tags list, find the tag with the polling interval of zero and select poll from the Actions list.
In the Poll Once dialog, copy the Topic. When you create a flow, you will paste this topic into the flow’s DataHub Publish node.
Create a Poll-Once Flow
Several flows can be created to illustrate the logic for a poll once scenario. In this example, create a flow that polls the device topic once based on the following logic:
- Continuously poll a register (for example, a switch for a pump’s motor), waiting for a state change.
- When the state changes (for example, the motor is turned on), trigger a “poll once” that subscribes to the message (for example, the temperature of the motor).
- Verify that the subscribe nodes are receiving the expected values.
To create a new flow:
- In the navigation pane, select Flows.
- Click Go to Flows.
- Drag the following nodes onto the canvas:
- DataHub Subscribe: Paste the raw topic for the device here to subscribe to the local DataHub data stream.
- json: Use this node to parse the
- DataHub Publish: Send message payload to DataHub. Paste the poll once device topic into this node. The poll once topic has the following format:
switch: Route messages based on the value detected. Use a switch for case logic such as:
If tag1 > 25, then start polling tag2 or If tag1 > 25, then start polling tag1 every 0.1 seconds
In the following example, two DataHub Publish nodes (configured with the poll once topic) receive the event message that triggers the device poll.