# Error Writing OPC-UA Node

**URL:** <https://forum.inductiveautomation.com/t/error-writing-opc-ua-node/45649>\
**Category:** Module Development\
**Tags:** ignition80\
**Created:** [April 15, 2021, 4:59pm UTC](https://forum.inductiveautomation.com/t/error-writing-opc-ua-node/45649 "2021-04-15T16:59:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [April 15, 2021, 4:59pm UTC](https://forum.inductiveautomation.com/t/error-writing-opc-ua-node/45649/1 "2021-04-15T16:59:03Z")

</div>

I am trying to write a tag that references a ManagedDevice implementation using the Milo OPC-UA driver.

The following is the error that the designer throws at me:

```auto
Error writing to InterMessageDelay.value: Bad("Bad_InternalError: An internal error occurred as a result of a programming or configuration error.")

```

The following is the snipped of my code that implements the write AttributeFilter:

```auto
UaVariableNode interMessageDelaysNode = UaVariableNode.builder(getNodeContext())
                .setNodeId(deviceContext.nodeId(String.format("%s/InterMessageDelay",folderName)))
                .setBrowseName(deviceContext.qualifiedName("InterMessageDelay"))
                .setDisplayName(new LocalizedText("InterMessageDelay"))
                .setDataType(BuiltinDataType.UInt32.getNodeId())
                .setTypeDefinition(Identifiers.BaseDataVariableType)
                .setAccessLevel(AccessLevel.READ_WRITE)
                .setUserAccessLevel(AccessLevel.READ_WRITE)
                .build();
        interMessageDelaysNode.setValue(new DataValue((new Variant(0))));
        interMessageDelaysNode.getFilterChain().addLast(AttributeFilters.getValue(
                getAttributeContext ->
                        new DataValue(new Variant(snmpDevice.getInterMessageDelay()))
                )
        );
        interMessageDelaysNode.getFilterChain().addLast(AttributeFilters.setValue((ctx, value) -> {
            snmpDevice.setInterMessageDelay((Integer) value.getValue().getValue());
            ctx.setAttribute(AttributeId.Value, value);
        }));
        getNodeManager().addNode(interMessageDelaysNode);
        folderNode.addOrganizes(interMessageDelaysNode);

```

Thanks,  
Brandon

---

<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:** [April 15, 2021, 5:00pm UTC](https://forum.inductiveautomation.com/t/error-writing-opc-ua-node/45649/2 "2021-04-15T17:00:31Z")

</div>

> [@brandon1](#):
>
> `snmpDevice.setInterMessageDelay((Integer) value.getValue().getValue());`

This line is probably causing a ClassCastException to be thrown and not caught by your code. You set the DataType to UInt32, so you should expect a `org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.UInteger` value.

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [April 15, 2021, 5:06pm UTC](https://forum.inductiveautomation.com/t/error-writing-opc-ua-node/45649/3 "2021-04-15T17:06:26Z")

</div>

Thank you for the quick response!

Here is the method signature inside my SNMPDevice class:

`public void setInterMessageDelay(int interMessageDelay){ this.interMessageDelay = interMessageDelay; }`

What is the correct way to pass only the value that is contained in DataType to this method?

---

<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:** [April 15, 2021, 5:07pm UTC](https://forum.inductiveautomation.com/t/error-writing-opc-ua-node/45649/4 "2021-04-15T17:07:54Z")

</div>

Easiest thing to do would be just change the DataType of your “InterMessageDelay” VariableNode to `BuiltinDataType.Int32`.

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [April 15, 2021, 5:12pm UTC](https://forum.inductiveautomation.com/t/error-writing-opc-ua-node/45649/5 "2021-04-15T17:12:35Z")

</div>

That would work except I’m using that variable to call sleep which takes a long as it’s input. So ultimately I will need this value to be a basic Java type.

---

<div class="post-metadata">

**Author:** ![brandon1](https://avatars.discourse-cdn.com/v4/letter/b/ea666f/32.png) [@brandon1](https://forum.inductiveautomation.com/u/brandon1)\
**Post date:** [April 15, 2021, 5:25pm UTC](https://forum.inductiveautomation.com/t/error-writing-opc-ua-node/45649/6 "2021-04-15T17:25:54Z")

</div>

Thanks again Kevin.

I found that UInteger has a intValue method and I changed my setValue filter to the following:

```auto
interMessageDelaysNode.getFilterChain().addLast(AttributeFilters.setValue((ctx, value) -> {
            UInteger uInteger = (UInteger) value.getValue().getValue();
            snmpDevice.setInterMessageDelay(uInteger.intValue());

            ctx.setAttribute(AttributeId.Value, value);
        }));

```

---

<div class="post-metadata">

**Author:** ![joshdunstan](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/joshdunstan/32/43306_2.png) [@joshdunstan](https://forum.inductiveautomation.com/u/joshdunstan)\
**Post date:** [May 8, 2023, 5:46am UTC](https://forum.inductiveautomation.com/t/error-writing-opc-ua-node/45649/7 "2023-05-08T05:46:31Z")

</div>

For anyone happening across this, I was seeing the same error message on a bulk write in one of my gateway scripts.

It was occurring because one of the tag values I was reading and then trying to write to another tag was of value 'null'.
