mikakaraila / node-red-contrib-opcua

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

Question: reconnecting to subscription tags on a rebooted server. #278

Closed youngkzy closed 3 years ago

youngkzy commented 3 years ago

QUESTION: Subscribed to arrays on Kepware OPC Server 6 and monitoring tags. During the weekend the OPC Server on a Windows Server was restarted and the connection was lost. This morning, I entered a new subscription to the data. What is the reccommended method to handle OPC Server disconnections and re-connections? The active subscription makes the connection, Is there a means to re-connect to an existing subscription? Otherwise I get duplicates as There is a subscription to the same tags multiple times.

Please see log entry below. Pending transactions: CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest

Warning : your opcua client is sending multiple requests simultaneously to the server CreateMonitoredItemsRequest Warning : please fix your application code

An Example of a means would be great if it already exists, I cannot locate it in the documentation. Thanks,

7 Mar 03:03:47 - [info] [OpcUa-Client:47dd96a3.f1d24] Local 'own' certificate is NOT used. 7 Mar 03:03:47 - [info] [OpcUa-Client:13644426.3baa04] Local 'own' certificate is NOT used. 7 Mar 03:03:47 - [info] [OpcUa-Client:b87d7f1f.99c9f8] Local 'own' certificate is NOT used. 7 Mar 03:03:47 - [info] [OpcUa-Client:8ccafbf8.94798] Local 'own' certificate is NOT used. 7 Mar 03:03:47 - [info] [OpcUa-Client:38becfeb.98bcf8] Local 'own' certificate is NOT used. 7 Mar 03:03:47 - [info] [OpcUa-Client:d553c505.0194e8] Local 'own' certificate is NOT used. 7 Mar 03:03:47 - [info] [OpcUa-Client:e8cd7ae1.5e03b8] Local 'own' certificate is NOT used. 7 Mar 03:03:47 - [info] [OpcUa-Client:f1b8fc45.3cbfc] Local 'own' certificate is NOT used. 7 Mar 03:03:47 - [info] [OpcUa-Client:3fc80617.5f26aa] Local 'own' certificate is NOT used. 7 Mar 03:03:47 - [info] [OpcUa-Client:513a9e47.2aa0d8] Local 'own' certificate is NOT used. 7 Mar 03:03:47 - [info] [OpcUa-Client:a873f9c4.c72ad8] Local 'own' certificate is NOT used. 7 Mar 03:03:47 - [info] [OpcUa-Client:6ac902f2.a5c424] Local 'own' certificate is NOT used. 7 Mar 03:03:47 - [info] Started flows 7 Mar 03:03:47 - [info] [tcp in:78cdb0e7.d8d6a8] listening on port 1026 7 Mar 03:03:47 - Connection successful for database with user undefined 7 Mar 03:03:47 - [info] [mqtt-broker:cec7206.b4cf76] Connected to broker: mqtt://localhost:1883 7 Mar 03:03:49 - [info] [OpcUa-Browser:5ccb2e21.230368] start browse client on opc.tcp://someplace:49320 7 Mar 03:03:49 - [info] [OpcUa-Browser:5ccb2e21.230368] start browse session on opc.tcp://someplace:49320 7 Mar 03:03:49 - [warn] [OpcUa-Browser:5ccb2e21.230368] browseTopic:ns=0;i=85 7 Mar 03:03:49 - [info] [OpcUa-Browser:88937ecb.49e6d8] start browse client on opc.tcp://someplace:49320 7 Mar 03:03:49 - [info] [OpcUa-Browser:c6451f87.abbce] start browse client on opc.tcp://127.0.0.1:49320 7 Mar 03:03:49 - [warn] [OpcUa-Browser:5ccb2e21.230368] sending items 9 7 Mar 03:03:49 - [warn] [OpcUa-Browser:5ccb2e21.230368] close browse session 7 Mar 03:03:49 - [info] [OpcUa-Browser:c6451f87.abbce] start browse session on opc.tcp://127.0.0.1:49320 7 Mar 03:03:49 - [warn] [OpcUa-Browser:c6451f87.abbce] browseTopic:ns=0;i=85 7 Mar 03:03:49 - [info] [OpcUa-Browser:88937ecb.49e6d8] start browse session on opc.tcp://someplace:49320 7 Mar 03:03:49 - [warn] [OpcUa-Browser:88937ecb.49e6d8] browseTopic:ns=0;i=85 Pending transactions: CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest CreateMonitoredItemsRequest Warning : your opcua client is sending multiple requests simultaneously to the server CreateMonitoredItemsRequest Warning : please fix your application code 7 Mar 03:03:49 - [warn] [OpcUa-Browser:88937ecb.49e6d8] sending items 9 7 Mar 03:03:49 - [warn] [OpcUa-Browser:88937ecb.49e6d8] close browse session 7 Mar 03:03:49 - [warn] [OpcUa-Browser:c6451f87.abbce] sending items 11 7 Mar 03:03:49 - [warn] [OpcUa-Browser:c6451f87.abbce] close browse session 8 Mar 08:19:39 - [warn] [OpcUa-Browser:88937ecb.49e6d8] input browser 8 Mar 08:19:39 - [info] [OpcUa-Browser:88937ecb.49e6d8] start browse client on opc.tcp://someplace:49320 8 Mar 08:19:39 - [info] [OpcUa-Browser:88937ecb.49e6d8] start browse session on opc.tcp://someplace:49320 8 Mar 08:19:39 - [warn] [OpcUa-Browser:88937ecb.49e6d8] browseTopic:ns=2;s=InstantInkSort1.InstantSort_CLX.Global.Gaylord_Data 8 Mar 08:19:39 - [warn] [OpcUa-Browser:88937ecb.49e6d8] sending items 22 8 Mar 08:19:39 - [warn] [OpcUa-Browser:88937ecb.49e6d8] close browse session 8 Mar 08:19:46 - [warn] [OpcUa-Browser:5ccb2e21.230368] input browser 8 Mar 08:19:47 - [info] [OpcUa-Browser:5ccb2e21.230368] start browse client on opc.tcp://someplace:49320 8 Mar 08:19:47 - [info] [OpcUa-Browser:5ccb2e21.230368] start browse session on opc.tcp://someplace:49320 8 Mar 08:19:47 - [warn] [OpcUa-Browser:5ccb2e21.230368] browseTopic:ns=2;s=InstantInkSort1.InstantSort_CLX.Global.Gaylord_MovePackage_x 8 Mar 08:19:47 - [warn] [OpcUa-Browser:5ccb2e21.230368] sending items 99 8 Mar 08:19:47 - [warn] [OpcUa-Browser:5ccb2e21.230368] close browse session

mikakaraila commented 3 years ago

If it is just lost connection, then server "keeps" subscription and nodeIds in it´s memory. But as server boots then everything is lost, client will try to create session, subscription etc. I cannot remember how long it will retry & how many times, depends on client parameters. Plus some servers can behave different way after reboot. You should test different cases: network break, server start, server boot.

youngkzy commented 3 years ago

@mikakaraila, Thanks for your quick reply. OK I can test this, but I'm also looking to "fix" by means of some flow logic and nodes to address it if it's not a "node" problem. It probably isn't your node. Kepware server reboots every night. I was using the system on my work PC to monitor some tags in a system for troubleshooting. It failed as the server rebooted... What recommendation do you have for this kind of problem using what is already there. The examples do not go into this kind of thing. Can I monitor NODE STATUS? (Node-RED Status Node) Or can I monitor a clock on the OPC Server system tags? Or can I monitor something from OPCUA node which tells me that the connection is broke in order to force a new connection? Now, I need to understand...

  1. when my subscription is no longer any good.. how to tell?
  2. ping or query the OPC Server to see if it is present.. ?? how to check OPC server is up? (after the file server is running).
  3. Determine if the subscription is old or still good? How to reconnect? or force a new reconnect when the server is back up.. It does look like it was trying a reconnect but the remote server was rebooting.

This kind of thing. No need to do the work for me. Good explanation should suffice as long as I can get the hows related to the nodes.

Thanks

mikakaraila commented 3 years ago

You can use Catch node to monitor node status, this way: image

It can be that computer is running, but OPC UA Server (KepServer) will crash. Then ping will not report it. If computer will crash then ping will detect it.

Or use READ Current time from the server, if current time is not updated.

youngkzy commented 3 years ago

@mikakaraila , Thanks for that advice. OK, So subscribing to an already set subscription is going to get me multiple values of the same tags when I add the same list to the subscription. How would I connect if I can sense that the subscription is still valid? And perhaps understand that it is still valid? Can I ask the system how many items are in the subscription? or get that from some reporting value in the node?

mikakaraila commented 3 years ago

You can see this so client will try to re-connect to server: image

Client contains re-connect code that is implemented inside node-opcua.

youngkzy commented 3 years ago

@mikakaraila , I do not know if I asked the question in the right way. Or maybe I'm a bit dense... If it is obvious, I'm overlooking it. Let's say...

  1. The remote OPC Server has been rebooted. I understand that I will need to SUBSCRIBE again to these tags and old subscription will not need to be deleted or UNSUBSCRIBED? I can ping and see if the server has been rebooted if lost ping maybe. I can see if the OPC Server is lost by checking date-time data OK.
  2. The remote OPC Server HAS NOT BEEN Rebooted. We lost the OPC Server or there was a connection glitch and it's not connected for some reason... I do not know how to force a reconnect to the same subscription(that should connect). Is that possible? How? Can I poll the connection? to see what my current Subscription is? or is possible? So I can A. UNSUBSCRIBE, or DELETE SUBSCRIPTION, Then Re-SUBSCRIBE...

Is it that if the loss of connection and a PING is available, then just DELETE the subscriptions and re-SUBSCRIBE? If the SUBSCRIBE fails, wait BROWSE and then SUBSCRIBE on Success of BROWSE? How would you do it such to correct a lost connection of type A, B, C, ... etc? Thanks in advance.

mikakaraila commented 3 years ago

1) I suppose client will try to connect again, create session and if server doesn´t return old subscription then library will create a new one. No need to do anything. 2) Same story client should first re-connect on network level and then do as in case 1)

Node-opcua makes life easy, don´t try to do it too complicated on the application level as library already handles it.

youngkzy commented 3 years ago

@mikakaraila , Again Thanks for your help. My problem is one that does not behave for some reason and it appears that it is stubborn. I came to work today to find my tags I am monitoring for debugging and writing to a log file are disconnected. And the status is RED under the SUBSCRIBE nodes. Thus the basis for these questions and my persistence. Sorry! The server may have been re-booted again. I was told that this should only happen on weekends. So I'm unsure of what transpired and working to find out. However, my logging did not work for the time which it found this fault. I applied my manual Inject nodes to initiate the SUBSCRIBE to get it back to working, as it was just sitting there. Kind Regards, @youngkzy

mikakaraila commented 3 years ago

It depends also on server how it behaves.

But as primary root cause is server boot, it would be better to solve it. Memory/driver problem or power supply...

youngkzy commented 3 years ago

@mikakaraila , The remote server in this case is supposed to re-boot on some weekly basis. That is for Windows updates etc... So, it's not THE problem, but it is a thing I need to deal with. I guess we are not quite on the same page. I am OK with it behaving this way on Kepware if that isn't an issue for anyone else. I require no extra attention except to get a clean way to get back to monitoring. I can use the method I described earlier IF that is the best way to approach it.

One question before I leave you... or assumption I want to verify. If the system for some reason has a subscription, but it disconnects, Is the only way to re-connect, to dump/delete the current subscription and Subscribe with a new one? assumption: there is no way to connect manually to a subscription. The only way I know to know how many items is from the subscription report in the messages.

Kind Regards,

mikakaraila commented 3 years ago

As server does not have any subscriptions after reboot, I suppose you can just create it again after ping works. Some delay most probably needed before KepServer is really running and accepting connections.