Skip to content

OPC UA list of variables in NodeRed

Hello all,

We would like to connect PLCNext to a (Rest)API of our customer. The connection is going to be used to achieve trend data to display in a graph. I've attached the flow we've come up with. We could make a connection by wiring all variables manually. But I like to make things "Smart", so I was wondering if there is a way to retrieve every variabel in NodeRed of the OPC UA server and create the link dynamically? In MQTT this is called a wildcard.

This way I don't need to change the NodeRed configuration when we want to add a trendvalue.

I'm also open for any other solution to create trenddata from the PLCNext variabel to the (Rest) API. Thanks in advance!

Comments

  • I think what you are looking for is browsing the OPC UA server for the available items. You can find an example here: OPC UA Browser. Please let me know if this helped to solve your problem.
  • Hi M.eerd,

    I'm not realy familar with Node.Red, but depending on the features of the UA Client package it should be possible to just browse the items.
    I've spent a few minutes on google and found this tutorial @Youtube, maybe this already does it...

    Otherwise there is also an interesting alternative using the PLCnext REST API. You can query all available variables with datatypes with the following calls:
    GET https://192.168.178.156/ehmi/data.dictionary.json
    

    will return:
    {"$schema":"http:\/\/json-schema.org\/draft-0\/schema#","title":"DataDictionary",
    "HmiVariables2":
    {"Arp.Plc.Eclr/ESM_DATA.ESM_INFOS[1].TICK_COUNT":{"Type":"DINT","InitValue":"0","ReadOnly":true},
    "Arp.Plc.Eclr/Test_Global":{"Type":"BOOL","InitValue":"FALSE"},
    "Arp.Plc.Eclr/Test_Global_GroupVar1":{"Type":"BOOL","InitValue":"FALSE"},
    "Arp.Plc.Eclr/Test_Global_GroupVar2":{"Type":"BYTE","InitValue":"BYTE#16#0"},
    "Arp.Plc.Eclr/Test_Global_GroupVar3":{"Type":"WORD","InitValue":"WORD#16#0"},
    "Arp.Plc.Eclr/Test_Global_GrouptVar4":{"Type":"DWORD","InitValue":"DWORD#16#0"},
    "Arp.Plc.Eclr/TestArray":{"Type":"arrByte_Stream","InitValue":""}
    }}
    

    and
    GET https://192.168.178.156/ehmi/type.dictionary.json
    

    will return:
    {"$schema":"http:\/\/json-schema.org\/draft-0\/schema#","title":"TypeDictionary",
    "Types":[
    {"Name":"DINT","RuntimeType":"System.Int32","RuntimeSize":4,"RuntimeAlignment":4,"Kind":"Elementary"},
    {"Name":"BOOL","RuntimeType":"System.Boolean","RuntimeSize":1,"RuntimeAlignment":1,"Kind":"Elementary"},
    {"Name":"BYTE","RuntimeType":"System.Byte","RuntimeSize":1,"RuntimeAlignment":1,"Kind":"Elementary"},
    {"Name":"WORD","RuntimeType":"System.UInt16","RuntimeSize":2,"RuntimeAlignment":2,"Kind":"Elementary"},
    {"Name":"DWORD","RuntimeType":"System.UInt32","RuntimeSize":4,"RuntimeAlignment":4,"Kind":"Elementary"},
    {"Name":"arrByte_Stream","RuntimeType":"ProConOS_eCLR.arrByte_Stream","RuntimeSize":28,"RuntimeAlignment":1,"Kind":"Array","ElementType":"BYTE","Dimensions":[{"StartIndex":0,"Length":28}]}]}
    

    So, with those two calls you can create a quite dynamic application.

    --> We're currently working on an update of the REST chapter, those two calls will be part of it.

    BR,
    Frank
  • Here is an example in node-red. It shows how you can browse the AXC OPC UA server. Just change the IP address and the namespace.
    I cannot upload the json file for some reason, so here is the plain code:

    [{"id":"76fbcb09.74594c","type":"tab","label":"Flow 1"},{"id":"c8b446ba.bfa058","type":"OpcUa-Browser","z":"76fbcb09.74594c","endpoint":"14afceca.6386f1","item":"","datatype":"","topic":"","items":[],"name":"","x":470,"y":40,"wires":[["47c865b3.8d2aac"]]},{"id":"481f49fe.55a3a8","type":"inject","z":"76fbcb09.74594c","name":"Browse","props":[{"p":"payload","v":"","vt":"str"},{"p":"topic","v":"","vt":"string"}],"repeat":"","crontab":"","once":false,"topic":"","payload":"","payloadType":"str","x":78.5,"y":35.79999542236328,"wires":"3eb58696.791f7a"},{"id":"3eb58696.791f7a","type":"function","z":"76fbcb09.74594c","name":"Set browse address","func":"msg.topic='ns=5;s=Arp.Plc.Eclr/INST_LevelControl1';\nmsg.actiontype='browse';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":251.50001525878906,"y":36,"wires":"c8b446ba.bfa058"},{"id":"47c865b3.8d2aac","type":"debug","z":"76fbcb09.74594c","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":710,"y":40,"wires":[]},{"id":"14afceca.6386f1","type":"OpcUa-Endpoint","endpoint":"opc.tcp://192.168.178.10:4840","secpol":"None","secmode":"None","login":false}]
  • First off all, thanks for the quick response. We will have to take look at the PLCNext REST API to read all the variables we'll need.
Sign In or Register to comment.