OPCFoundation / UA-.NETStandard

OPC Unified Architecture .NET Standard
Other
1.95k stars 945 forks source link

Add support for restoring (re-linking) of triggered monitored items upon session reconnect #2095

Open htbmw opened 1 year ago

htbmw commented 1 year ago

Type of issue

Current Behavior

I am developing an OPC UA connector (client) that can create subscriptions that contain monitored items that are linked to a triggering item via the Session.SetTriggering method.

Documentation about this approach can be found here: https://reference.opcfoundation.org/Core/Part4/v105/docs/5.12.1.6#_Ref288138179

When I stop the opcua server and restart it, my connector (client) reconnects as soon as the opcua server is online. The subscriptions and their monitored items are retained, but the linking of monitored items and their respective triggering items are gone.

Digging in the code I see a lot of code where the session and subscriptions are recreated upon reconnect, but nowhere the links between triggering items and their monitored items can be seen, which explains why triggered notifications don't work after a reconnect.

Could support for this be built into the underlying SDK?

Expected Behavior

After having created a subscription with triggering items, as soon as the opcua server has restarted and the client has reconnected to the server triggered notifications should resume normally as they did before the reconnect.

Steps To Reproduce

Start opc ua server Start a client that connects to the server On the client, create and link monitored items with a triggering item and start the subscription Observe that notifications are received when the trigger item is triggered Stop the server Observe that the clients detects the disconnection Start the server Observe that the client reconnects to the server Observe that triggered notifications don't work like they did before the reconnect.

Environment

- OS: Windows 10, Ubuntu
- Environment: Visual Studio 2022
- Runtime: .Net 6.0
- Nuget Version: Project references from master branch
- Component: Opc.Ua.Client
- Server: Reference Server
- Client: Own developed connector

Anything else?

Currently I work around this by maintaining a table of trigger items and their linked monitored items, and in the On_ReconnectComplete I will call the SetTriggering method again for all subscriptions and all associated linked items and triggers. It requires a lot of leg-work to correlate items and their triggers and locate the new id's on the new reconnected session. I have to make extensive use of the ClientHandle to join the original items and the new items after the reconnect.

mregen commented 1 year ago

Great feedback, thanks. we need to investigate...