5:02, EEST
May 29, 2020
Hi,
I am wondering if it is possible for a client to add new NodeID
I try to use this code in client
AddNodesItem item = new AddNodesItem(client.getNamespaceTable().toExpandedNodeId(parentNodeId),//.toExpandedNodeId(parentNode),
Identifiers.HasComponent,//referenceTypeId,
client.getNamespaceTable().toExpandedNodeId(newNodeId),
browseName,
NodeClass.ObjectType,
ExtensionObject.binaryEncode(nodeAttributes, client.getEncoderContext()),
ExpandedNodeId.NULL);
and Server return
com.prosysopc.ua.ServiceException: ServiceFault: Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.”
Diagnostic Info: ServiceResult=Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.”
Caused by: ServiceFault: Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.”
then I find can use
Server.getAddressSpace().setNodeManagementEnabled(true);
in Server SDK to unlock UserAccess
but it still return Bad_ServiceUnsupported (0x800B0000)
how to and where to insert “Server.getAddressSpace().setNodeManagementEnabled(true);”
or other function in Server should to modify?
is there any sample code for add new nodeId to Server from client request (Client/Server)
thanks~
11:20, EEST
Moderators
February 11, 2020
Hello,
You can put “Server.getAddressSpace().setNodeManagementEnabled(true);” towards the end of the initialization of the UaServer instance in your Server application code. If you are working with SampleConsoleServer sample application, you can put it to the very end of initialize-method in SampleConsoleServer class.
In order to add Nodes to a Server, you must connect to the Server non-anonymously. However, you can also modify your NodeManagerListener to allow anonymous users to add Nodes. In SampleConsolerServer sample’s case, you would modify MyNodeManagerListener class and remove calls of checkUserAccess-method.
When creating AddNodesItem instances, you also have to make sure that the NodeAttributes instance is of the correct subtype. In your case, you should use an instance of ObjectTypeAttributes class as the value of nodeAttributes variable. Failing to do so and attempting to use an instance of NodeAttributes class instead will also cause a Bad_ServiceUnsupportedException.
BR,
Matti
5:34, EEST
May 29, 2020
Matti Siponen said
Hello,You can put “Server.getAddressSpace().setNodeManagementEnabled(true);” towards the end of the initialization of the UaServer instance in your Server application code. If you are working with SampleConsoleServer sample application, you can put it to the very end of initialize-method in SampleConsoleServer class.
In order to add Nodes to a Server, you must connect to the Server non-anonymously. However, you can also modify your NodeManagerListener to allow anonymous users to add Nodes. In SampleConsolerServer sample’s case, you would modify MyNodeManagerListener class and remove calls of checkUserAccess-method.
When creating AddNodesItem instances, you also have to make sure that the NodeAttributes instance is of the correct subtype. In your case, you should use an instance of ObjectTypeAttributes class as the value of nodeAttributes variable. Failing to do so and attempting to use an instance of NodeAttributes class instead will also cause a Bad_ServiceUnsupportedException.
BR,
Matti
Hi Matti
Thanks for your help!!
I want to add a Variable node in parents node (ns=2;i=5001)
this is my source code
NodeId typeDefinition = null;
NodeClass nodeClass = NodeClass.Variable;
NodeId parentNode2= new NodeId(2,”5001″);
NodeId referenceTypeId2= Identifiers.BaseDataVariableType;
ObjectAttributes objectAttributes= new ObjectAttributes();
objectAttributes.setDescription(LocalizedText.english(“I am a Object Node”));
objectAttributes.setSpecifiedAttributes(UnsignedInteger.ONE);
objectAttributes.setUserWriteMask(UnsignedInteger.ONE);
objectAttributes.setWriteMask(UnsignedInteger.ONE);
ObjectAttributes nodeAttributes4 = objectAttributes;
NodeId newNodeId2 = new NodeId(2,”6011″);
QualifiedName browseName2=new QualifiedName(“TonyAddTest”);
nodeAttributes.setDisplayName(new LocalizedText(“TonyAddTest”));
AddNodesItem item = new AddNodesItem(client.getNamespaceTable().toExpandedNodeId(parentNode2),
referenceTypeId2, client.getNamespaceTable().toExpandedNodeId(newNodeId2), browseName2,
NodeClass.ObjectType, ExtensionObject.binaryEncode(nodeAttributes4, client.getEncoderContext()),
ExpandedNodeId.NULL);
Server return no Bad_ServiceUnsupportedException
but I still can’t see new node ns=2 i=6011
how to fix this wrong?
thanks!!
10:45, EEST
Moderators
February 11, 2020
Hello,
When adding a Node with AddNodesItem, you must set its parameters as defined in OPC UA Specification Part 4, https://reference.opcfoundation.org/v104/Core/docs/Part4/5.7.2/
In the code you provided, you were using incorrect NodeClass, the NodeAttributes didn’t match the NodeClass and the ReferenceType and TypeDefinition were not set correctly. If you fix these mistakes, you will be able to add the Node.
In general, we don’t debug programs on this forum so I won’t write the code for you, but I will help you understand the API if you have any questions related to it.
5:25, EEST
May 29, 2020
Matti Siponen said
Hello,When adding a Node with AddNodesItem, you must set its parameters as defined in OPC UA Specification Part 4, https://reference.opcfoundation.org/v104/Core/docs/Part4/5.7.2/
In the code you provided, you were using incorrect NodeClass, the NodeAttributes didn’t match the NodeClass and the ReferenceType and TypeDefinition were not set correctly. If you fix these mistakes, you will be able to add the Node.
In general, we don’t debug programs on this forum so I won’t write the code for you, but I will help you understand the API if you have any questions related to it.
Hi Matti:
Thanks
I update my code as follow
NodeId parentNode = new NodeId(2,”5001″);
NodeId referenceTypeId =Identifiers.BaseDataVariableType;
NodeId newNodeId = new NodeId(2,”6011″);
QualifiedName browseName = new QualifiedName(2,”name”);
ObjectAttributes objectAttributes = new ObjectAttributes();
objectAttributes.setDisplayName(new LocalizedText(“name”));
AddNodesItem item = new AddNodesItem(
client.getNamespaceTable().toExpandedNodeId(parentNode),
Identifiers.BaseDataVariableType,
client.getNamespaceTable().toExpandedNodeId(newNodeId),
new QualifiedName(2,”TonyTestAdd”),
NodeClass.Variable,
ExtensionObject.binaryEncode(objectAttributes, client.getEncoderContext()),
ExpandedNodeId.NULL);
NodeId Id = client.getAddressSpace().addNode(item);
1.NodeClass is set ==> NodeClass.Variable,
2.NodeAttributes is set ==> ExtensionObject.binaryEncode(objectAttributes, client.getEncoderContext())
3.TypeDefinition is set ==> ExpandedNodeId.NULL
Server return Bad_ServiceUnsupported (0x800B0000) “The server does not support the requested service.” again
Is the client correct? or Server not support ?
but I already inserted
put “Server.getAddressSpace().setNodeManagementEnabled(true);” in the init() of SampleConsoleServer code
and mark the server MyNodeManagerListener.java function onAddNode close the checkUserAccess(serviceContext);
thanks~~
9:13, EEST
April 3, 2012
Hi,
Sorry that this post is very long, but I do not think anything shorter would explain it in required detail here. Also please try to understand the advice we give. If you want us to implement your software, you can buy our https://www.prosysopc.com/services/ . Additionally it should be noted that all this is one way or another information you could (and to some extent should, at least for the basics) have obtained by yourself by reading the tutorials, javadoc, samples and partly from OPC UA knowledge that you sort of need to have (or learn by yourself or by attending a workshop etc.). Also note that it takes 3 full workdays to just explain the basics of OPC UA in the context of a workshop, and we are now (in my personal opinion) far beyond what would even be considered as OPC UA basics. The documentation could of course be always better.
The NodeManagement service set (add/remove nodes and references) is somewhat less used feature. A typical OPC UA Server does not allow using it. It is also very dangerous to allow clients to do that, unless you either ensure that all clients are trusted (i.e. not using the None MessageSecurityMode and you trust all clients on equal level) or make proper authorization (for every NodeManager), for what the MyNodeManagerListener example (even if a bit differently) shows. Otherwise a client could e.g. DeleteNodes the Server node, which would be bad.
Additionally usually you will need some extra logic written to the server to actually do anything useful with the nodes added. Also in normal cases you most likely would want the nodes to survive a restart (so you would need to pass the info to the backend of the data as well).
Your code is incorrect and does not make sense OPC UA wise. Also it should be noted that OPC UA has literally 1000s of features. We do our best to provide nice API to use, but the reality is that we cannot do everything (or well like eventually hopefully yes). The API releated to the AddNodes is quite raw, it is only basically as the raw service call level. Using those basically means that you will need to know the OPC UA Specification or alternatively be willing to learn it yourself if you do not know it already. Thus please read and understand the url Matti said. Per your code it would seem you have not done that. And as extra clarification, typically using a “service call level” API needs to go 100% right or it just wont work.
Now for the issue, I’ll try to list all relevant here just for the sake of completeness as I might use this thread in the future to explain this.
– parentNode, Needs to exist, must be OPC UA -wise a valid node i.e. parent to the new node + reference combination (basically the only way to know these is to read the specification or just know it)
– referenceTypeId, MUST be a NodeId pointing to a ReferenceType node. You have used BaseDataVariableType here, that is incorret, usually something like Identifiers.HasComponent or Organizes is a good starting point. For more info read Part 3 (https://reference.opcfoundation.org/v104/Core/docs/Part3/) and 5 (https://reference.opcfoundation.org/v104/Core/docs/Part5/). There are more rules than SDK would enforce (and sometimes we need to be able to work with invalid models as well, but not all invalid combinations work with the SDK).
– newNodeId, must not yet exist, it is also the equivalent NodeManager for that namespace who’s listener is queried for the listener part (that I explained at the start)
– browseName, used as the BrowseName Attribute, usually has the same namespace index than the newNodeId
– nodeClass, the NodeClass of the new node to be added. This is really important. This determines which sort of “base type” the node is, i.e. this defines which Attributes the node can have. They are explained in Part 3.
– nodeAttributes, This must EXACTLY match the NodeClass used, i.e. if NodeClass is Object, then this must be ObjectAttributes. For ObjectType it must be ObjectTypeAttributes and for Variable VariableAttributes (and for VariableType VariableTypeAttributes). Basically if nodeClass is NodeClass.XXX this must be XXXNodeAttributes. Additionally it should be noted that OPC UA v1.04 added a GenericAttributes, which we do not yet support.
– typeDefinition, IF you use NodeClass.Variable OR NodeClass.Object, then this Must be a valid (Expanded)NodeId pointing to a TypeDefinition of the respective type you which to instantiate on the server side. If you want to make a simple Variable node, then the BaseDataVariableType would be a good option here. IF you are not making Variable nor Object, then this must be the NULL, as no other NodeClasses can have a TypeDefinition (which is then a HasTypeDefition Reference from the Variable->VariableType or Object->ObjectType in the address space)
Please note that if you make a Variable (or well applies to all, but you would run into this next), you must also set all the Attributes of the VariableAttributes you pass to the AddNodesItem, you will need to decide on a DataType (which must be a NodeId that is a valid DataType node) and ValueRank (scalar, array, multidim array, and few exotic options) and if an array in some cases the ArrayDimensions. These are explained in the Part 3 of the Specification.
P.S.
Nowadays we do have e.g. ReferenceTypeIdentifiers that list just the ReferenceType nodeids of the standard model, we do have one for each nodeclass. SDK also includes Ids class, which behaves the same as Identifiers, but contains ExpandedNodeIds and VariableTypeIds thus would contain all ExpandedNodeIds of the standard model that are of nodeclass VariableType (though it should be noted that the Ids contains only info from the typespace and misses “Server” node related ids).
Most Users Ever Online: 1919
Currently Online:
78 Guest(s)
Currently Browsing this Page:
2 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 88
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 739
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1524
Posts: 6453
Newest Members:
shaylamaggard4, rickyjuarez140, jonathonmcintyre, fannielima, kristiewinkle8, rust, christamcdowall, redaahern07571, nigelbdhmp, travistimmonsModerators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1027, Jimmy Ni: 26, Matti Siponen: 346, Lusetti: 0
Administrators: admin: 1