Programming Node-RED Flows for Live PLC Monitoring
Programming Node-RED Flows for Live PLC Monitoring
With Node-RED now successfully connected to the simulated PLC via OPC UA, I began developing logic-driven flows to make real-time data meaningful and accessible. This part of the project focused on structuring data reads, interpreting values through conditional logic, and preparing everything for display on a user-facing dashboard.
The idea was to transform raw tag values, like Boolean outputs from sensors or integer counters from the PLC, into readable, actionable information. To achieve this, Node-RED’s visual programming environment allowed me to chain together several components: inject nodes (to trigger actions), OPC UA item readers, function nodes for logic processing, and output nodes for debugging or display.
To simulate continuous monitoring, I configured Node-RED to poll key PLC variables at regular intervals. This was accomplished by pairing inject nodes (set to repeat every 0.5 seconds) with OPC UA item nodes, each of which referenced a specific tag from the PLC. Tags included sensor statuses, actuator states, and system counters—most of which had been configured as symbolic addresses within the TIA Portal project.
This polling loop effectively emulated the live behaviour of a factory monitoring system. Rather than waiting for user input, the dashboard could update autonomously, reflecting the state of the digital twin in near real-time.
Raw OPC UA outputs from Siemens PLCs tend to come through in structured JSON formats. For example, a sensor signal might appear as:
{"value": true, "datatype": "Boolean"}
While technically accurate, this isn’t very readable. To translate these into human-friendly terms, I introduced function nodes immediately downstream of the OPC UA item readers. Each function node contained custom logic that interpreted the value and assigned a more descriptive output.
This approach was applied consistently across multiple parts of the system, including detecting whether the gripper was in position, whether the stopper was engaged, or if a separator arm had triggered. Each node converted low-level data into clear operational status messages
Some monitoring elements require correlation between several signals. For example, to properly assess the state of the Pick and Place station, I needed to know both the gripper’s vertical position and the presence of a base part under it. Node-RED allows for such multi-tag analysis through its switch node, which waits for a predefined set of messages and merges them into a single object. This enabled me to build conditional logic around full station behaviour.
The Node-RED logic layer effectively turned my digital twin from a passive simulation into an intelligent, monitored environment. Rather than just observing mechanical motion, I now had the tools to:
Interpret sensor feedback.
Track part progress and counters.
Flag abnormal conditions.
This logic layer also served as the foundation for the next phase: visualising system states on a user-friendly dashboard.