Scenario: Monitor Normalized IoT Data, Send Commands, and Email Alerts
Dequeue normalized OCI IoT data in Node-RED, send a reset command when Boiler pressure exceeds a threshold, poll the command status, and publish a success, failure, or timeout email alert.
Use this scenario to monitor data already received by OCI IoT and take action when a condition is met.
The flow dequeues normalized data, sends a reset command when Boiler pressure exceeds 100, and polls the command status in the IoT database. A final result continues to the notification nodes. A non-final result loops through a five-second delay and queries the command status again.
In this scenario, IoT data is already inside OCI IoT, so the Flow Runtime acts as a lightweight event processor without requiring an application to access the IoT database directly. You can adapt this pattern for alerting, creating tickets, downstream notifications, and other operational automations.
Complete the common scenario setup before starting.
Tasks
Prerequisites
- An OCI Notifications topic and its OCID.
- A Flow Runtime Resource Principal configuration with the related Notifications and digital twin command-invoke policies.
Add the Notifications policy to let the Flow Runtime resource principal publish messages to the scenario topic.
Allow dynamic-group <flow-runtime-dynamic-group> to {ONS_TOPIC_PUBLISH} in compartment <notification-topic-compartment>Add the digital twin command-invoke policy to let the resource principal request a command.
Allow dynamic-group <flow-runtime-dynamic-group> to {IOT_DIGITAL_TWIN_INSTANCE_COMMAND_INVOKE} in compartment <iot-domain-compartment> - An IoT domain database connection available to the Dequeue and SQL nodes.
- The gateway external key and device password recorded when you completed the common digital twin instance setup. The examples use
fr-guide-gw-01as the gateway external key. - The OCIDs and external keys of the Boiler digital twin instances monitored by the flow.
- To validate a successful reset, a device-side command handler that receives the request at
boilers/<external-key>/command/resetand returns a response atboilers/<external-key>/command/response.
Step 1: Creating the Monitoring Flow Runtime
Step 2: Configuring the Monitoring and Command Node-RED Flow
Step 3: Creating an Email Subscription
Step 4: Subscribing to the Command Request Endpoint
Step 5: Generating a High Boiler Pressure Message
Use the gateway external key as the device user name and the gateway device password as the password. Replace
<domain-short-id-from-device-host>,<region>, and<gateway-device-password>with the values for your environment.curl -i -X POST \ -u "fr-guide-gw-01:<gateway-device-password>" \ -H "Content-Type: application/json" \ "https://<domain-short-id-from-device-host>.device.iot.<region>.oci.oraclecloud.com/boilers/fr-guide-boiler-01" \ -d '{ "temperature": 83, "pressure": 102 }'Using the same Gateway-authenticated MQTT connection, publish a high-pressure Boiler message with these settings:
Field Value Topic boilers/fr-guide-boiler-01QoS 1Payload type JSON { "temperature": 83, "pressure": 102 }
Step 6: Sending the Command Response
Step 7: Validating the Polling Flow and Email Notification
Security Considerations
Use the Flow Runtime Resource Principal to publish only to approved Notifications topics and invoke commands only on approved digital twin instances. Limit the notification and command payloads to the operational fields that recipients require, and protect the IoT domain database connection, queue subscriber, and command response data.
Troubleshooting
- Confirm the queue name, subscriber, JSON payload type, wait value, batch size of
2, and IoT domain database connection. - Use a Debug node to confirm that the normalized record exposes
digitalTwinInstanceId,contentPath,value, andtimeObserved. - Confirm that
boilerExternalKeyMapcontains only the exact Boiler digital twin OCIDs and matching digital twin instance external keys. HVAC pressure records are ignored because their OCIDs aren't mapped. To find an external key, see Getting a Digital Twin's Instance Details or to change the external key, see Updating a Digital Twin Instance. - Confirm that the IoT Send Command node uses the Resource Principal configuration, receives
msg.digitalTwinOcid,msg.requestEndpoint, andmsg.responseEndpoint, and has Wait for response selected. - Confirm that the Gateway MQTT client stays connected and subscribed to the exact request endpoint before the flow sends the command. Without an active subscriber, the command immediately finishes with
DELIVERY_STATUSset toREFUSED. - Confirm that the device-side command handler listens on the request endpoint and publishes its result to the response endpoint before the response duration expires.
- Confirm that Initialize Command Status Polling sets
msg.pollDeadlineandmsg.pollCountbefore the first delay. - If the SQL node returns no row, confirm that
msg.rawCommandDataRecordIdis present after the IoT Send Command node and is mapped to therecordIdbind variable. Before the deadline, a missing row must continue through output 2 of Check Command Status. - Confirm that output 1 of Check Command Status connects to Format Boiler Command Result Notification and output 2 connects back to Wait Before Status Check.
- If the reset is reported as failed, inspect
DELIVERY_STATUS,RESET_RESULT, andTIME_FINISHEDinRAW_COMMAND_DATA. The final statuses areCOMPLETED,REJECTED,REFUSED,EXPIRED,BAD_RESPONSE, andNOT_RESPONDED. - If the flow reports
POLL_TIMEOUT, confirm that the Delay node uses five seconds and that the command did not reach a final status before the 70-second deadline. - Confirm the Notifications topic OCID, Resource Principal configuration, permission to publish messages, and active email subscription.
For more information, see Troubleshooting IoT Flow Runtimes and Flow Runtimes FAQs.
FAQs
- Why must the email subscription be active?
- OCI Notifications doesn't deliver the alert to an email subscription while its state is Pending. Follow the confirmation link before testing the flow.
- Why does the flow query the command status every five seconds?
- The short delay lets the flow detect a final command status without waiting for the complete response window. A non-final result loops back to the Delay node and is queried again.
- Why is the polling deadline 70 seconds?
- The command response duration is
PT1M. The additional ten seconds allow OCI IoT to apply the final database update before the flow reportsPOLL_TIMEOUT. - Which queue records does this flow evaluate?
- The flow dequeues JSON records from
<domain-short-id>__IOT.NORMALIZED_DATA. It evaluatespressureevents only when the digital twin OCID is present inboilerExternalKeyMap, so HVAC pressure records and unmapped Boiler records are ignored. - When does the notification report a successful reset?
- The reset succeeds only when
DELIVERY_STATUSisCOMPLETEDand the response JSON containsreset: SUCCESS. Other final results use the failed-reset notification, while a missing final result at the deadline uses the timeout notification. - Why did the command finish with
REFUSED? - The Gateway MQTT client wasn't connected and actively subscribed to the exact command request endpoint when the flow sent the command. Subscribe to
boilers/fr-guide-boiler-01/command/resetbefore triggering the flow. - Can I generate the test data through the live-ingestion scenario?
- Yes. This scenario publishes directly to the IoT device-host topic
boilers/fr-guide-boiler-01. If you keep the live broker ingestion flow running instead, publish the same payload tosource/boilers/fr-guide-boiler-01on the public broker.