Restore connection after server restart|OPC UA Standard|Forum|OPC Foundation

Avatar
Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
Lost password?
sp_Feed sp_PrintTopic sp_TopicIcon
Restore connection after server restart
Avatar
Mirko Collura
Member
Members
Forum Posts: 6
Member Since:
05/29/2017
sp_UserOfflineSmall Offline
1
07/06/2017 - 08:38
sp_Permalink sp_Print

Hi, how can the client restore the session (with subscription and monitoredItem inside) on Server after Server restart?

Without create new session, subscription and monitoredItem.

I tried  session.Reconnect()  but it throw BadSessionIdInvalid exception.

And i tried session.Recreate(session) , in this case ServerState becomes Running, but client not receices event on monitoreItem “Notification” event.

Thanks.

Avatar
Guest
Guests
2
07/06/2017 - 23:18
sp_Permalink sp_Print

OPC UA Sessions are not persisted. I.e. when a Server restarts, all Sessions are lost. Restoring / reconnecting in this situation is not possible.

Avatar
Paul Hunkar
Cleveland, Ohio, USA
Moderator
Members

Moderators-Specifications

Moderators-Companion

Moderators-Implementation

Moderators-Certification

Moderators-COM
Forum Posts: 112
Member Since:
02/24/2014
sp_UserOfflineSmall Offline
3
07/06/2017 - 23:44
sp_Permalink sp_Print

If the Server supports “durable subscriptions” then a client can establish a new session and then reclaim the old subscription following a server restart.  The client has to establish a new connection to the server with the same security context.  The Server should have maintained all data, only loosing any data that changed while it was down/restarting.  Durable Subscriptions was a new feature in 1.03.

Paul Hunkar - DSInteroperability

Avatar
Mirko Collura
Member
Members
Forum Posts: 6
Member Since:
05/29/2017
sp_UserOfflineSmall Offline
4
07/07/2017 - 07:46
sp_Permalink sp_Print sp_EditHistory

Thanks for answers!!

In the end i recreated session and subscription.

Added the list of MonitoredItem (that i had previously stored in a List) at new subscription.

But i noticed that MonitoredItems were not created on Server at subscription.Create() time because they had a monitoredItem.Status.Created = true.

I think that I’ve used a workaroud: i’ve call  monitoredItem.SetDeleteResult(new StatusCode(1),nothing,Nothing,nothing)  foreach monitoredItem before adding them to subscription.

Now, all works fine!

Avatar
Mirko Collura
Member
Members
Forum Posts: 6
Member Since:
05/29/2017
sp_UserOfflineSmall Offline
5
07/10/2017 - 23:06
sp_Permalink sp_Print

It is fair to use this workaround to obtain MonitoredItems with Status.Created  false?

Avatar
Guest
Guests
6
07/11/2017 - 22:59
sp_Permalink sp_Print

It seems that your issues relate to the UA Software you are using. If you use UA Software from the OPC Foundation public source repositories (e.g. https://github.com/OPCFoundati…..ardLibrary) please enter an issue into the issue list of this repository.

The moderators of this forum have good knowledge of the OPC UA standard but not necessarily of the implementations.

Avatar
Vegard Hellerud
Member
Members
Forum Posts: 4
Member Since:
10/12/2015
sp_UserOfflineSmall Offline
7
10/05/2018 - 06:24
sp_Permalink sp_Print

Hei,

A related question.

I am building a OPC UA Client. I am able to create a subscription containing some Monitoreditems.

On the OPC UA server these monitored items change value constantly.

I want to disconnect the client and wait for a while. Then I reconnect having my subscriptions back, but I also want all the monitored Item values queued up during the disconnect.

I am settin a queuesize:

monitoredItem.QueueSize = 100;

 

How to capture the content of the queue after a disconnect???

 

if (node.Displayname == “The node I want to monitor”)
{
MonitoredItem mon = CreateMonitoredItem((NodeId)node.reference.NodeId, node.Displayname);
m_subscription.AddItem(mon);
m_subscription.ApplyChanges();
subscribedClientNodes.Add(node);
}

————

private MonitoredItem CreateMonitoredItem(NodeId nodeId, string displayName)
{
if (m_subscription == null)
{

m_subscription = new Subscription(m_session.DefaultSubscription);

m_subscription.PublishingEnabled = true;
m_subscription.PublishingInterval = 3000;//1000;
m_subscription.KeepAliveCount = 10;
m_subscription.LifetimeCount = 10;
m_subscription.MaxNotificationsPerPublish = 1000;
m_subscription.Priority = 100;
bool cache = m_subscription.DisableMonitoredItemCache;

m_session.AddSubscription(m_subscription);

m_subscription.Create();
}

// add the new monitored item.
MonitoredItem monitoredItem = new MonitoredItem(m_subscription.DefaultItem);
//Each time a monitored item is sampled, the server evaluates the sample using a filter defined for each monitoreditem.
//The server uses the filter to determine if the sample should be reported. The type of filter is dependent on the type of item.
//DataChangeFilter for Variable, Eventfilter when monitoring Events. etc
//MonitoringFilter f = new MonitoringFilter();
//DataChangeFilter f = new DataChangeFilter();
//f.DeadbandValue

monitoredItem.StartNodeId = nodeId;
monitoredItem.AttributeId = Attributes.Value;
monitoredItem.DisplayName = displayName;
//Disabled, Sampling, (Report (includes sampling))
monitoredItem.MonitoringMode = MonitoringMode.Reporting;
//How often the Client wish to check for new values on the server. Must be 0 if item is an event.
//If a negative number the SamplingInterval is set equal to the PublishingInterval (inherited)
//The Subscriptions KeepAliveCount should always be longer than the SamplingInterval/PublishingInterval
monitoredItem.SamplingInterval = 500;
//Number of samples stored on the server between each reporting
monitoredItem.QueueSize = 100;
monitoredItem.DiscardOldest = true;//Discard oldest values when full
monitoredItem.CacheQueueSize = 100;

monitoredItem.Notification += m_MonitoredItem_Notification;

if (ServiceResult.IsBad(monitoredItem.Status.Error))
{
return null;
}

return monitoredItem;
}

——

private void MonitoredItem_Notification(MonitoredItem monitoredItem, MonitoredItemNotificationEventArgs e)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new MonitoredItemNotificationEventHandler(MonitoredItem_Notification), monitoredItem, e);
return;
}

try
{
if (m_session == null)
{
return;
}

MonitoredItemNotification notification = e.NotificationValue as MonitoredItemNotification;

if (notification == null)
{
return;
}

foreach(MonitoredItem mon in monitoredItem.Subscription.MonitoredItems)
{
MonitoredItemNotification v = mon.LastValue as MonitoredItemNotification;
richTextBox1.AppendText(“
Iteration: ” + mon.DisplayName + ” value: ” + v.Value.Value + “sTime: “+v.Value.SourceTimestamp+” status: ” + mon.Status.QueueSize.ToString());
}
string sess = m_session.SessionId.Identifier.ToString();
string s = string.Format(“
MonitoredItem: {0}\t Value: {1}\t Status: {2}\t SourceTimeStamp: {3}”, monitoredItem.DisplayName, (notification.Value.WrappedValue.ToString().Length == 1) ? notification.Value.WrappedValue.ToString() + ” ” : notification.Value.WrappedValue.ToString(), notification.Value.StatusCode.ToString(), notification.Value.SourceTimestamp.ToLocalTime().ToString(“HH:mm:ss.fff”));
richTextBox1.AppendText(s + “
SessionId: ” + sess);
}
catch (Exception exception)
{
ClientUtils.HandleException(this.Text, exception);
}
}

Avatar
Jim Luth
Moderator
Members

Moderators-Specifications
Forum Posts: 5
Member Since:
04/15/2014
sp_UserOfflineSmall Offline
8
10/15/2018 - 05:25
sp_Permalink sp_Print

In order for a Client to completely disconnect from a Server and later reconnect to a previous Subscription and retrieve the queued values:

  1. The Server must support the feature “durable Subscriptions” (not many Servers support this feature !!!)
  2. The Client must explicitly set the Subscription durable by calling the SetSubscriptionDurable Method.

See Clause 6.8 of OPC UA Part 4 https://opcfoundation.org/UA/Part4/ for more details to use this feature.

Avatar
Vegard Hellerud
Member
Members
Forum Posts: 4
Member Since:
10/12/2015
sp_UserOfflineSmall Offline
9
10/18/2018 - 06:52
sp_Permalink sp_Print

Hi Jim,

Thanks for your reply!

Had a look in chapter 6.8 like you said.

Durable subscription seems like what I really need!

Actually I’m creating both the OPC UA server and client so I would have to implement the Durable subscription myself then. 

You mentioned not many servers support this feature….I agree. I have been searching for a while to see any examples on how to implement this from the .NET C# SDK. Not found anything yet!!!

If anyone have some more details or examples on implementation I would be very happy!

 

Thanks!

Forum Timezone: America/Phoenix
Most Users Ever Online: 510
Currently Online:
Guest(s) 40
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Forum Stats:
Groups: 2
Forums: 10
Topics: 1445
Posts: 4889