# Loading tags after opc ua device restart

**URL:** <https://forum.inductiveautomation.com/t/loading-tags-after-opc-ua-device-restart/79492>\
**Category:** Module Development\
**Created:** [September 22, 2023, 8:35am UTC](https://forum.inductiveautomation.com/t/loading-tags-after-opc-ua-device-restart/79492 "2023-09-22T08:35:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Fekete](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@Sebastian\_Fekete](https://forum.inductiveautomation.com/u/Sebastian_Fekete)\
**Post date:** [September 22, 2023, 8:35am UTC](https://forum.inductiveautomation.com/t/loading-tags-after-opc-ua-device-restart/79492/1 "2023-09-22T08:35:11Z")

</div>

I am developing a custom module based on the OPC UA device example. When a device is running, folders and tags are created. When the device gets disabled, all tags are set to bad quality. When i enable the device, i have to delete it in the Tag Browser in the designer and put it in again so that the tags and folders are updating. This is because i always create new instances of folders and tags in my module. Instead i want that the tags work without dragging the device again and again into the tag browser. In my onStartup i try to get all tags with this approach:

```auto
  dataItems = deviceContext.getSubscriptionModel().getDataItems(deviceContext.getName());

```

but dataItems is always empty, i also tried to get the references but nothing worked out.  
this is what happens in the onShutdown (when device gets disabled or deleted):

```auto
private void onShutdown() {
        deviceContext.getSubscriptionModel()
                .getDataItems(deviceContext.getName())
                .forEach(item -> item.setQuality(new StatusCode(StatusCodes.Uncertain_LastUsableValue)));
        subscriptionModel.shutdown();
        deviceContext.getGatewayContext()
            .getExecutionManager()
            .unRegister(EuromapDeviceType.TYPE_ID, deviceContext.getName());
        euromapDataMonitor.stopFileWatch();
    }

```

How can i use the folders and tags that were created at the first start of the device?

---

<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:** [September 22, 2023, 12:08pm UTC](https://forum.inductiveautomation.com/t/loading-tags-after-opc-ua-device-restart/79492/2 "2023-09-22T12:08:17Z")

</div>

> [@Sebastian\_Fekete](#):
>
> ```auto
> dataItems = deviceContext.getSubscriptionModel().getDataItems(deviceContext.getName());
> 
> ```

This is the approach used by all the other drivers too. It shouldn't be empty, it should have any existing DataItem created by any client, and represents the things your driver needs to poll or otherwise update after it starts.

You shouldn't need to be dragging and dropping tags from the OPC browser to the Tag browser again.

---

<div class="post-metadata">

**Author:** ![Sebastian\_Fekete](https://avatars.discourse-cdn.com/v4/letter/s/a698b9/32.png) [@Sebastian\_Fekete](https://forum.inductiveautomation.com/u/Sebastian_Fekete)\
**Post date:** [September 25, 2023, 8:07am UTC](https://forum.inductiveautomation.com/t/loading-tags-after-opc-ua-device-restart/79492/3 "2023-09-25T08:07:34Z")

</div>

Is there a way to convert the Data Items to a UaVariableNode so that i can update the values etc. ?

---

<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:** [September 25, 2023, 12:38pm UTC](https://forum.inductiveautomation.com/t/loading-tags-after-opc-ua-device-restart/79492/4 "2023-09-25T12:38:17Z")

</div>

Sorry that question just doesn't make any sense.

Regardless of what Data Items exist, you should be creating the same Nodes every time your driver starts. The Nodes represent the data your driver is making available.

Data Items (Monitored Items) represent a request from a client to sample/monitor a particular attribute of a particular node.
