CreateMonitoredItems failed: BadNodeIdUnknown

Questions regarding the use of the C++ SDK for Server or Client development or integration into customer products ...

Moderator: uasdkcpp

Post Reply
Bradyh98
Jr. Member
Jr. Member
Posts: 4
Joined: 23 Oct 2019, 23:11

CreateMonitoredItems failed: BadNodeIdUnknown

Post by Bradyh98 »

Hello,

I am using the C++ SDK for Client development. In particular, I need to read values from a KEPServerEX 6. I have followed the tutorial/lessons for the Client development.

Here is my setup.ini

Code: Select all

[UaSampleConfig]
CertificateTrustListLocation        =pkiclient/trusted/certs/
CertificateRevocationListLocation   =pkiclient/trusted/crl/
IssuersCertificatesLocation         =pkiclient/issuers/certs/
IssuersRevocationListLocation       =pkiclient/issuers/crl/
ClientCertificate                   =pkiclient/own/certs/GettingStartedClient.der
ClientPrivateKey                    =pkiclient/own/private/GettingStartedClient.pem
Username                          =Default User
Password                          =Mcs-7270

ApplicationName         =VIZAdapterOPCUA
;DiscoveryURL            =opc.tcp://98H8DC2.TechSolve.org:49320
ServerUrl               =opc.tcp://127.0.0.1:49320
AutomaticReconnect      =true
RetryInitialConnect     =false

NSArray/size            =1
NSArray/NameSpaceUri00  =urn:98H8DC2.TechSolve.org:Kepware.KEPServerEX.V6:UAServer

NodesToRead/size        =1
NodesToRead/Variable00  =ns=0;s=Channel1.Device1.Tag

NodesToMonitor/size         =1
NodesToMonitor/Variable00   =ns=0;s=Channel1.Device1.Tag
In the Kepware I have a tage with the id: Channel1.Device1.Tag

Here is the code where the issue is printed

Code: Select all

UaStatus Subscription::createMonitoredItems()
{
	if (m_pSubscription == NULL)
	{
		printf("\nError: No Subscription created\n");
		return OpcUa_BadInvalidState;
	}
	UaStatus result;
	OpcUa_UInt32 size, i;
	ServiceSettings serviceSettings;
	UaMonitoredItemCreateRequests itemsToCreate;
	UaMonitoredItemCreateResults createResults;
	// Configure items to add to the subscription
	UaNodeIdArray lstNodeIds = m_pConfiguration->getNodesToMonitor();
	size = lstNodeIds.length();
	itemsToCreate.create(size);
	for (i = 0; i < size; i++)
	{
		itemsToCreate[i].ItemToMonitor.AttributeId = OpcUa_Attributes_Value;
		OpcUa_NodeId_CopyTo(&lstNodeIds[i], &itemsToCreate[i].ItemToMonitor.NodeId);
		itemsToCreate[i].RequestedParameters.ClientHandle = i;
		itemsToCreate[i].RequestedParameters.SamplingInterval = 500;
		itemsToCreate[i].RequestedParameters.QueueSize = 1;
		itemsToCreate[i].RequestedParameters.DiscardOldest = OpcUa_True;
		itemsToCreate[i].MonitoringMode = OpcUa_MonitoringMode_Reporting;
	}
	printf("\nAdding monitored items to subscription ...\n");
	result = m_pSubscription->createMonitoredItems(
		serviceSettings,
		OpcUa_TimestampsToReturn_Both,
		itemsToCreate,
		createResults);
	if (result.isGood())
	{
		// check individual results
		for (i = 0; i < createResults.length(); i++)
		{
			if (OpcUa_IsGood(createResults[i].StatusCode))
			{
				printf("CreateMonitoredItems succeeded for item: %s\n",
					UaNodeId(itemsToCreate[i].ItemToMonitor.NodeId).toXmlString().toUtf8());
			}
			else
			{
				printf("CreateMonitoredItems failed for item: %s - Status %s\n",
					UaNodeId(itemsToCreate[i].ItemToMonitor.NodeId).toXmlString().toUtf8(),
					UaStatus(createResults[i].StatusCode).toString().toUtf8());
			}
		}
	}
	// service call failed
	else
	{
		printf("CreateMonitoredItems failed with status %s\n", result.toString().toUtf8());
	}
	return result;
}

Code: Select all

OpcUa_IsGood(createResults[i].StatusCode)

is always evaluated as false.

Any advice would be appreciated.

Bradyh98
Jr. Member
Jr. Member
Posts: 4
Joined: 23 Oct 2019, 23:11

Re: CreateMonitoredItems failed: BadNodeIdUnknown

Post by Bradyh98 »

I have been able to fix my issue.

The next question is: how do I get the actual value read from the NodeId?

Code: Select all

UaNodeId(itemsToCreate[i].ItemToMonitor.NodeId).toXmlString().toUtf8());

Post Reply