# OPC-UA Driver Allow Reading without Predefined Nodes

**URL:** <https://forum.inductiveautomation.com/t/opc-ua-driver-allow-reading-without-predefined-nodes/53267>\
**Category:** Module Development\
**Created:** [November 18, 2021, 10:50pm UTC](https://forum.inductiveautomation.com/t/opc-ua-driver-allow-reading-without-predefined-nodes/53267 "2021-11-18T22:50:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Noah\_Killian](https://avatars.discourse-cdn.com/v4/letter/n/76d3ee/32.png) [@Noah\_Killian](https://forum.inductiveautomation.com/u/Noah_Killian)\
**Post date:** [November 18, 2021, 10:50pm UTC](https://forum.inductiveautomation.com/t/opc-ua-driver-allow-reading-without-predefined-nodes/53267/1 "2021-11-18T22:50:31Z")

</div>

Hello, I am attempting to create a new OPC UA Driver extending ManagedDevice. I have a working implementation using predefined nodes for all data being accessed. Now, I am trying to make it more dynamic and since there may be a rather large amount of possible nodes, I would rather be able to access them in a method similar to the Modbus Driver with the “ns=1;s=[device]HRF1234” methodology.

I am able to perform direct OPC reads via the Script console at this point but I cannot figure out the subscription bit for usage with tags. The tags are giving an “Error\_Configuration” message, though they work with my old driver. I am addressing the various attributes using values I found by logging a predefined diagnostic node. Here is what I am trying for a node that is not in the NodeManager:

```java
String nodeName = getNodeName(id.getNodeId());
DataValue value = httpJsonHandler.getValue(nodeName);
AttributeId attributeId = AttributeId.from(id.getAttributeId()).get();
Object v;
switch (attributeId)
{
    case AccessLevel:
        v = AccessLevel.READ_ONLY;
        break;
    case UserAccessLevel:
        v = AccessLevel.READ_ONLY;
        break;
    case EventNotifier:
        v = null;
        break;
    case MinimumSamplingInterval:
        v = -1.0;
        break;
    case DataType:
        v = BuiltinDataType.Float.getNodeId();
        break;
    default:
        v = null;
        break;
}

if (attributeId == AttributeId.Value)
    results.add(value);
else
    results.add(new DataValue(new Variant(v)));   

```

I tried logging the onDataItemsCreated and only the predefined node appeared. I couldn’t find any docs on the ManagedDevice but I have been basing everything so far on Milo’s ManagedAddressSpaceServices. Any help you can offer would be appreciated.

Thank you,  
Noah

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [November 18, 2021, 10:59pm UTC](https://forum.inductiveautomation.com/t/opc-ua-driver-allow-reading-without-predefined-nodes/53267/2 "2021-11-18T22:59:30Z")

</div>

ManagedDevice (and all the Managed\* Milo classes) might be the wrong approach for having dynamically addressable Nodes, but you can probably still get it to work by overriding the `read` and `write` methods at the very least. Implementing just `onDataItemsCreated` isn’t enough - you’ll never get far enough to have that called for a dynamically addressed Node if `read` isn’t implemented to return attributes for those Nodes.

If your device implementation will be entirely dynamic and not a hybrid then the “Managed” abstractions are probably wrong for you all together. They basically just take care of implementing browse, read, and write based on the assumption all Nodes will be registered with the NodeManager. If that’s not going to be true at all you may as well just implement `Device` directly.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [November 18, 2021, 11:02pm UTC](https://forum.inductiveautomation.com/t/opc-ua-driver-allow-reading-without-predefined-nodes/53267/3 "2021-11-18T23:02:21Z")

</div>

> [@Kevin.Herron](#):
>
> just implement `Device` directly

💯

Avoiding a full implementation of `Device` is not really an option if you want dynamic node creation. Well, unless you implement the older `Driver` interface instead (ahem, cough).

---

<div class="post-metadata">

**Author:** ![Noah\_Killian](https://avatars.discourse-cdn.com/v4/letter/n/76d3ee/32.png) [@Noah\_Killian](https://forum.inductiveautomation.com/u/Noah_Killian)\
**Post date:** [November 22, 2021, 9:41pm UTC](https://forum.inductiveautomation.com/t/opc-ua-driver-allow-reading-without-predefined-nodes/53267/4 "2021-11-22T21:41:31Z")

</div>

I appreciate the advice. That at least gives me some direction for the future. I think I will dig into the full Device implementation at some point. For now, I am just adding Nodes to the node manager as needed in the read method and then removing them if they haven’t been accessed in a while.

---

<div class="post-metadata">

**Author:** ![neil.thornton](https://avatars.discourse-cdn.com/v4/letter/n/a3d4f5/32.png) [@neil.thornton](https://forum.inductiveautomation.com/u/neil.thornton)\
**Post date:** [February 28, 2022, 2:49pm UTC](https://forum.inductiveautomation.com/t/opc-ua-driver-allow-reading-without-predefined-nodes/53267/5 "2022-02-28T14:49:55Z")

</div>

That is exactly what I want to do but don’t know how to implement the read method  
some pointers please , i am also using the ManagedDevice
