mikakaraila / node-red-contrib-opcua

A Node-RED node to communicate OPC UA. Uses node-opcua library.
Other
214 stars 196 forks source link

How to expose Context variables to OPC Server. #534

Open youngkzy opened 1 year ago

youngkzy commented 1 year ago

I have looked at the Node-RED Forum and help. I used the browser to discover tags. I get a message "Browse to root Objects". I have Server, Aliases, DeviceSet, NetworkSet, DeviceTopology, VendorName. How do I get to Node, Flow, and Global variables as tags? I'd like to be able to set variables to be available to the OPC Server.

youngkzy commented 1 year ago

I copied the example OPC Server and I'm seeing some issues. Injected "Translation" and this is what I got.

3/9/2023, 10:51:40 PMnode: 11682102.b5b9af msg : string[42] "Mandatory parameter 'namespace' is missing" 3/9/2023, 10:51:40 PMnode: 11682102.b5b9af msg : string[90] "warning: properties like messageType, namespace, variableName or VariableValue is missing."

mikakaraila commented 1 year ago

Cannot access links, but according the warning message your msg object / payload does not contain needed properties.

youngkzy commented 1 year ago

This is the function. I'm not sure how or what to put in for the missing items. Namespace etc.

msg = { payload : { "messageType" : "Variable", "variableName": "Counter", "variableValue": msg.payload }}; return msg;

Help me put this together. These are obviously not node, flow or global variables. How can I set up Node, Flow or Global context variables to be part of the OPCUA server?

Thanks.

youngkzy commented 1 year ago

My experience with OPCUA is moderate to advanced, meaning, I can get pretty much figure it out eventually. But I'm confused. The list of commands below do not ever mention the word "Tag". Is this OPCUA Server defining tags by variables and the message alters the variable content which is conveyed by the message? I expected the OPC Server to work like a PLC which has memory address as a tag and the content is conveyed when the tag content changes. (subscribe) . Does this OPC Server work similarly to apply node, flow or global context variables to "Tag"?

OPC UA server commands:

restartOPCUAServer addEquipment addPhysicalAsset setFolder addFolder addVariable installHistorian installDiscreteAlarm installLimitAlarm addExtensionObject deleteNode registerNamespace getNamespaceIndex getNamespaces setUsers addFile saveAddressSpace loadAddressSpace bindVariables bindMethod

youngkzy commented 1 year ago

I need help. The example renders errors and I'm not sure how to fix it. I'm asking what I thought was a simple question . How to get context variables to a tag. There is no mention of the word "Tag" in the documentation.

What is the relationship to the server for these items? are these tags? or are they hierarchical leafs? Equipment.PhysicalAsset.person.tag?

Please help me connect the dots. If I create a context variable named "test", How do I get it listed on the server for me to monitor with a test client?

Equipment Physical Asset Person

mikakaraila commented 1 year ago

Look again OPCUA-TEST-NODES.json and tab NodeRED UA-Server.

AddVariable will insert new OPC UA variable into the address space, itcontains these fields: msg.payload = {"opcuaCommand":"addVariable"} msg.topic = ns=1;s=TestAddVariable1;datatype=Float

To set variable value this message structure is used: image

Here is example flow to use variables: OPCUA-VARIABLE.txt

youngkzy commented 1 year ago

Success! Thank you dearly for providing this last example. The inject nodes set up the variables and "explain" what is necessary to set the server tags. I'm monitoring with a READ Client and inject "ns=1;s=TestVariable".

Thank you,

youngkzy commented 1 year ago

Testing this out I substituted 0 as a number with insert "Set TestVariable2 12.3 + ts + quality (Good Number)". After sending it with the values of anything else like 2161770496 the OPC Server does not respond with with the Number 0. You must set it to Good with the Text value = "Good". Is this a bug with node-opcua or node-red-contrib-opcua?

mikakaraila commented 1 year ago

Be more specific, cannot understand what you mean?

All status codes are defined here: https://github.com/node-opcua/node-opcua/blob/master/packages/node-opcua-status-code/source/_generated_status_codes.ts

mikakaraila commented 1 year ago

If you want to set quality as text must be string and it must be found from the statuscodes:

 if(typeof(payload.quality)==='string') { 
                                // a name of Quality was given -> convert it to number
                                verbose_log("Getting numeric status code of quality: " + payload.quality);
                                payload.quality = opcua.StatusCodes[payload.quality].value;
 }

Other wise code will use it as numeric and convert it: var statusCode = opcua.StatusCode.makeStatusCode(payload.quality);