@opcua/for-node-red
Version:
The Node-RED node to communicate via OPC UA, powered NodeOPCUA and developed by Sterfive's team
112 lines (111 loc) • 4.04 kB
JSON
[
{
"id": "9f075ff2e2a04c12",
"type": "tab",
"label": "OPCUA Server - basic",
"disabled": false,
"info": "",
"env": []
},
{
"id": "780fb182a24ec3fd",
"type": "function",
"z": "9f075ff2e2a04c12",
"name": "Create Basic OPCUA Server with one counter variable",
"func": "// Demonstrates the GLOBALS path — works under `functionExternalModules: false`.\n//\n// No `libs:` Setup-tab entry. No settings.js edit. The Sterfive palette\n// populates `global.get(\"sterfive\")` at startup via bootstrapOnce(); user\n// code reaches into it instead of importing.\nconst sterfive = global.get(\"sterfive\");\nif (!sterfive) {\n node.error(\"global.get('sterfive') is not set — is opcua-for-nodered loaded?\");\n} else {\n const { bootstrap, opcua } = sterfive;\n const { bootstrapServer } = bootstrap;\n\n const cfg = msg.config || {};\n\n const handle = await bootstrapServer({\n port: cfg.port ?? 4840,\n endpoint: cfg.endpoint || \"node-red-server\",\n nodesets: [\n \"standard\",\n \"di\",\n \"ia\",\n \"machinery\"\n ],\n onPopulate: (addressSpace, exposed) => {\n\n const ns = addressSpace.getOwnNamespace();\n exposed.myCounter = ns.addVariable({\n organizedBy: \"RootFolder\",\n nodeId: \"s=Counter\",\n browseName: \"Counter\",\n dataType: \"Double\",\n value: { dataType: \"Double\", value: 3.14 },\n });\n },\n });\n\n flow.set(\"$myCounter\", handle.exposed.myCounter);\n\n node.send({ payload: `OPC UA Server (globals path) running at ${handle.server.getEndpointUrl()}` });\n}\n",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 540,
"y": 140,
"wires": [
[
"a6b49c71d09a9b8c"
]
]
},
{
"id": "de0711735c90a8cf",
"type": "inject",
"z": "9f075ff2e2a04c12",
"name": "Start Server",
"props": [
{
"p": "config",
"v": "{ \"port\": 26550 }",
"vt": "json"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 210,
"y": 140,
"wires": [
[
"780fb182a24ec3fd"
]
]
},
{
"id": "a6b49c71d09a9b8c",
"type": "debug",
"z": "9f075ff2e2a04c12",
"name": "debug output",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 850,
"y": 200,
"wires": []
},
{
"id": "838a2f9ddea59a54",
"type": "function",
"z": "9f075ff2e2a04c12",
"name": "update OPCUA counter variable",
"func": "var v = flow.get(\"$myCounter\");\nconst value = v.readValue()\nvalue.value.value += 1;\nv.setValueFromSource(value.value)\nreturn { ...msg, payload: value.value.value };",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 470,
"y": 240,
"wires": [
[
"a6b49c71d09a9b8c"
]
]
},
{
"id": "18ea982bc2a9e0e5",
"type": "inject",
"z": "9f075ff2e2a04c12",
"name": "Count Up",
"props": [],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 200,
"y": 240,
"wires": [
[
"838a2f9ddea59a54"
]
]
}
]