Search code examples
javasubscriptionopcopc-ua

OPC UA Java - How to get MonitoredItemID from a subscription publishResponse


I'm currently working with the OPC UA Foundation Java Stack, without any additional SDK's.

I managed to implement subscriptions with multiple monitored items and I'm getting the change notifications correctly via the publish response.

The Problem is that I can not figure out which monitored item is responsible for the datachange response, when I have multiple items in one subscription. The MonitoredItemNotification doesn't seem to have a method for that?! So how can I get an itemId, displayname, nodeId or just anything to identify the item in the response?

This is the response I get(looks almost identically for each item):

ResponseHeader=ResponseHeader
Timestamp=06/23/16 10:36:41.9018551 GMT
RequestHandle=0
ServiceResult=GOOD (0x00000000) ""
ServiceDiagnostics=Diagnostic Info: 

StringTable=class java.lang.String[0]
AdditionalHeader=null
SubscriptionId=92
AvailableSequenceNumbers=class org.opcfoundation.ua.builtintypes.UnsignedInteger[2]
[0]=1
[1]=2
MoreNotifications=false
NotificationMessage=NotificationMessage
SequenceNumber=2
PublishTime=06/23/16 10:36:41.9018551 GMT
NotificationData=class org.opcfoundation.ua.builtintypes.ExtensionObject[1]
  [0]=DataChangeNotification: DataChangeNotification
    MonitoredItems=class org.opcfoundation.ua.core.MonitoredItemNotification[1]
      [0]=MonitoredItemNotification
      ClientHandle=0
      Value=DataValue(value=true, statusCode=GOOD (0x00000000) "", sourceTimestamp=06/23/16 10:36:41.7146527 GMT, sourcePicoseconds=0, serverTimestamp=null, serverPicoseconds=0)
    DiagnosticInfos=class org.opcfoundation.ua.builtintypes.DiagnosticInfo[0]

Results=class org.opcfoundation.ua.builtintypes.StatusCode[0]
DiagnosticInfos=class org.opcfoundation.ua.builtintypes.DiagnosticInfo[0]

Solution

  • Each MonitoredItem shall have its own ClientHandle.

    When you send a CreateMonitoredItems Request to the server you should pass the ClientHandle you want in each MonitoredItemCreateRequest. This will be returned in each Publish Response's MonitoredItemNotification.

    I guess you passed the value "0", that's why you have

    [0]=MonitoredItemNotification
      ClientHandle=0
      Value=DataValue(value=true, statusCode=GOOD (0x00000000) "", sourceTimestamp=06/23/16 10:36:41.7146527 GMT, sourcePicoseconds=0, serverTimestamp=null, serverPicoseconds=0)