Subscribe to Multiple OPC UA Values and Store in PostgreSQL with Node-RED
This Node-RED flow subscribes to several data points from an OPC UA server using OpcUa-Item nodes and stores the incoming values in a PostgreSQL database. It's ideal for industrial data logging, historical analysis, and traceability. The flow includes data formatting, timestamping, and database insertion using the node-red-contrib-postgresql node.
[{"id":"6cfd054dc9ca4e78","type":"OpcUa-Item","z":"a3771d5a74a10df6","item":"","datatype":"Double","value":"","name":"Subscribe Data","x":540,"y":780,"wires":[["6ef151c1f28b2977"]]},{"id":"e0487877ecc3aa65","type":"inject","z":"a3771d5a74a10df6","name":"Subscribe Data","props":[],"repeat":"","crontab":"","once":true,"onceDelay":"","topic":"","x":340,"y":780,"wires":[["6cfd054dc9ca4e78","e92643ed5fa4df40","3d4a745f6ef3c95c"]]},{"id":"6ef151c1f28b2977","type":"OpcUa-Client","z":"a3771d5a74a10df6","endpoint":"","action":"subscribe","deadbandvalue":"","time":"1","timeUnit":"s","localfile":"","localkeyfile":"","useTransport":false,"maxChunkCount":"","maxMessageSize":"","receiveBufferSize":"","sendBufferSize":"","setstatusandtime":false,"keepsessionalive":false,"name":"OPC UA Client","x":740,"y":780,"wires":[["f0d994d0f4a9bbde","5f65f2b4d33dafb6","e424ac113f73f4c4"],[],[]]},{"id":"f0d994d0f4a9bbde","type":"debug","z":"a3771d5a74a10df6","name":"Result Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1100,"y":720,"wires":[]},{"id":"5f65f2b4d33dafb6","type":"ui_text","z":"a3771d5a74a10df6","group":"","order":0,"width":0,"height":0,"name":"","label":"text","format":"{{msg.payload}}","layout":"row-spread","className":"","x":1070,"y":760,"wires":[]},{"id":"371f29b2e8547a1e","type":"OpcUa-Client","z":"a3771d5a74a10df6","endpoint":"","action":"subscribe","deadbandvalue":"","time":"1","timeUnit":"s","localfile":"","localkeyfile":"","useTransport":false,"maxChunkCount":"","maxMessageSize":"","receiveBufferSize":"","sendBufferSize":"","setstatusandtime":false,"keepsessionalive":false,"name":"OPC UA Client","x":740,"y":880,"wires":[["f0b7e232f2dda5e0","7d37b99b70c30a5b","050fa30ced729b5c"],[],[]]},{"id":"f0b7e232f2dda5e0","type":"debug","z":"a3771d5a74a10df6","name":"Result Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1100,"y":840,"wires":[]},{"id":"e92643ed5fa4df40","type":"OpcUa-Item","z":"a3771d5a74a10df6","item":"","datatype":"Double","value":"","name":"Subscribe Data","x":540,"y":880,"wires":[["371f29b2e8547a1e"]]},{"id":"80593ab0b05e9b6a","type":"OpcUa-Client","z":"a3771d5a74a10df6","endpoint":"","action":"subscribe","deadbandvalue":"","time":"1","timeUnit":"s","localfile":"","localkeyfile":"","useTransport":false,"maxChunkCount":"","maxMessageSize":"","receiveBufferSize":"","sendBufferSize":"","setstatusandtime":false,"keepsessionalive":false,"name":"OPC UA Client","x":740,"y":960,"wires":[["c602591f349951c3","535ee6552e788a39","e1cb2ea117501afb"],[],[]]},{"id":"c602591f349951c3","type":"debug","z":"a3771d5a74a10df6","name":"Result Output","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1100,"y":960,"wires":[]},{"id":"3d4a745f6ef3c95c","type":"OpcUa-Item","z":"a3771d5a74a10df6","item":"","datatype":"Double","value":"","name":"Subscribe Data","x":540,"y":960,"wires":[["80593ab0b05e9b6a"]]},{"id":"7d37b99b70c30a5b","type":"ui_gauge","z":"a3771d5a74a10df6","name":"","group":"","order":0,"width":0,"height":0,"gtype":"gage","title":"gauge","label":"units","format":"{{value}}","min":0,"max":10,"colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","diff":false,"className":"","x":1070,"y":880,"wires":[]},{"id":"535ee6552e788a39","type":"ui_chart","z":"a3771d5a74a10df6","name":"","group":"","order":0,"width":0,"height":0,"label":"chart","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"","ymax":"","removeOlder":1,"removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"useUTC":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"outputs":1,"useDifferentColor":false,"className":"","x":1070,"y":1000,"wires":[[]]},{"id":"e424ac113f73f4c4","type":"postgresql","z":"a3771d5a74a10df6","name":"","query":"INSERT INTO opcua_data (node_id, value, data_type, timestamp)\nVALUES ($1, $2, $3, $4);","postgreSQLConfig":"","split":false,"rowsPerMsg":1,"outputs":1,"x":1090,"y":800,"wires":[[]]},{"id":"050fa30ced729b5c","type":"postgresql","z":"a3771d5a74a10df6","name":"","query":"INSERT INTO opcua_data (node_id, value, data_type, timestamp)\nVALUES ($1, $2, $3, $4);","postgreSQLConfig":"","split":false,"rowsPerMsg":1,"outputs":1,"x":1090,"y":920,"wires":[[]]},{"id":"e1cb2ea117501afb","type":"postgresql","z":"a3771d5a74a10df6","name":"","query":"INSERT INTO opcua_data (node_id, value, data_type, timestamp)\nVALUES ($1, $2, $3, $4);","postgreSQLConfig":"","split":false,"rowsPerMsg":1,"outputs":1,"x":1090,"y":1040,"wires":[[]]}]