open62541

How to set different object view by 'logged in' user?


Let's say I have two users - UserA & UserB. When UserA connect to my OPC-UA Server based on open62541 I want him to see:

Data
    - MyData1
    - MyData2
    - MyData3

When UserB connect I want him to see:

Data
    - MyData1

Is it possible? and if so where do I use it when I set an object node

UA_Server_addObjectNode(UA_Server *server, 
                    const UA_NodeId requestedNewNodeId,
                    const UA_NodeId parentNodeId,
                    const UA_NodeId referenceTypeId,
                    const UA_QualifiedName browseName,
                    const UA_NodeId typeDefinition,
                    const UA_ObjectAttributes attr,
                    void *nodeContext, 
                    UA_NodeId *outNewNodeId)

Solution

  • You can not do that directly via the UA_Server_addObjectNode.

    The concept you are looking for in OPC UA is called Views.

    From the OPC UA Specification, Part 3:

    View NodeClass

    Underlying systems are often large and Clients often have an interest in only a specific subset of the data. They do not need, or want, to be burdened with viewing Nodes in the AddressSpace for which they have no interest.

    To address this problem, this standard defines the concept of a View. Each View defines a subset of the Nodes in the AddressSpace. The entire AddressSpace is the default View. Each Node in a View may contain only a subset of its References, as defined by the creator of the View. The View Node acts as the root for the Nodes in the View. Views are defined using the View NodeClass, which is specified in Table 5.

    All Nodes contained in a View shall be accessible starting from the View Node when browsing in the context of the View. It is not expected that all containing Nodes can be browsed directly from the View Node but rather browsed from other Nodes contained in the View.

    A View Node may not only be used as additional entry point into the AddressSpace but as a construct to organize the AddressSpace and thus as the only entry point into a subset of the AddressSpace. Therefore Clients shall not ignore View Nodes when exposing the AddressSpace. Simple Clients that do not deal with Views for filtering purposes can, for example, handle a View Node like an Object of type FolderType (see 5.5.3)

    So what you need to do is create a View Node, and attach the corresponding nodes to this View Node. The user can then start browsing from that specific view.

    The corresponding method is called UA_Server_addViewNode. Then use the UA_Server_addReference method to reference other nodes within your created view node. The reference type should be Organizes.