# Problem by using node-red-contrib-opcua for PLC backup

**URL:** <https://discourse.nodered.org/t/problem-by-using-node-red-contrib-opcua-for-plc-backup/101182>\
**Category:** General\
**Created:** [3 June 2026 15:42 UTC](https://discourse.nodered.org/t/problem-by-using-node-red-contrib-opcua-for-plc-backup/101182 "2026-06-03T15:42:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Petonius](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@Petonius](https://discourse.nodered.org/u/Petonius)\
**Post date:** [3 June 2026 15:42 UTC](https://discourse.nodered.org/t/problem-by-using-node-red-contrib-opcua-for-plc-backup/101182/1 "2026-06-03T15:42:55Z")

</div>

Hi,  
I have a problem with reading out data from PLC to make a backup.  
I use node-red-contrib-opcua client node and Browser node for it.  
The data(Recipes of a machine) are send to specified datablock of Siemens S7-1500 PLC on demand.  
There is a raw description how it should works:

**1)** The recipes are stored on HMI on indices(0-49). First I will write an Index, which data I wish to receive. There is used write request to opc client.

**2)** Then I should toggle the Export variable to make PLC Export the data for chosen Index. There is used write request to opc client.

**3)** Then I should read out all prepared data from PLC. I use Browser node for this.

I try it to do in such a structure see pict below.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/3/e3329ed1ae5cbed5c16e6eb761f0d83407eb3b4f.png)

function22 - prepared the messages and send them to output for OPC UA Client to get data prepared(1) and 2)) and to second output to OPC UA Browser to retrieve the data.  
It sends the messages with delay of 2s till all indices(0-49) are covered.  
There is a code in **function 22** :

```js
const delay = 2000; // ms
let i = 0;
let arr1 = ['"ns=3;s="NV_ExpImp_Recipe"."Recipe_data"','ns=3;s="NV_ExpImp_Command"."Index";','ns=3;s="NV_ExpImp_Command"."Export";']; //Array of values for Payloads of three messages needed to receive data from PLC
let arr2 = ['','Int16','Boolean',];//Array of values for Datatypes of three messages needed to receive data from PLC
let arr3 =[0,"true","",1,"true","",2,"true","",3,"true","",4,"true","",5,"true","",
6,"true","",7,"true","",8,"true","",9,"true",10,"true","",11,"true","",
12,"true","",13,"true","",14,"true","",15,"true","",16,"true","",17,"true","",
18,"true","",19,"true","",20,"true","",21,"true","",22,"true","",23,"true","",
24,"true","",25,"true","",26,"true","",27,"true","",28,"true","",29,"true","",
30,"true","",31,"true","",32,"true","",33,"true","",34,"true","",35,"true","",
36,"true","",37,"true","",38,"true","",39,"true","",40,"true","",41,"true","",
42,"true","",43,"true","",44,"true","",45,"true","",46,"true","",47,"true","",
48,"true","",49,"true",];
//Array of values for Topics of three messages needed to receive data from PLC

// Each 2000ms will be send one message to PLC over OPC: 1. to select index, 2. to toggle the 
let interval = setInterval( () => {
    // Each third message is for second output of functional node - opc browser
    let a=((i+1)%3);
    if(a==0){
      //in case of 3. message use the second output of function node
   node.send([null, { payload: arr3[i], topic: arr1[a], datatype: arr2[a] } ]);  
    }else{
    node.send({ payload: arr3[i], topic: arr1[a], datatype: arr2[a] } );
    }
    i++;
    if (i == arr3.length) {//after sending all 150 messages end the automatic sending
        clearInterval(interval);
    }
}, delay);

```

function23 just prepare the data to create a file.

I can write Data from 8 Indices to a file and then I become following error and the Node red terminates:

```auto
[red] Uncaught Exception:
4 Jun 15:18:58 - [error] Error: expecting a number NaN
    at coerceVariantType (C:\Users\inoxcz\.node-red\node_modules\node-opcua-variant\dist\variant.js:631:23)
    at constructHook (C:\Users\inoxcz\.node-red\node_modules\node-opcua-variant\dist\variant.js:415:25)
    at new Variant (C:\Users\inoxcz\.node-red\node_modules\node-opcua-variant\dist\variant.js:79:26)
    at write_action_input (C:\Users\inoxcz\.node-red\node_modules\node-red-contrib-opcua\opcua\102-opcuaclient.js:1870:22)
    at OpcUaClientNode.processInputMsg [as _inputCallback] (C:\Users\inoxcz\.node-red\node_modules\node-red-contrib-opcua\opcua\102-opcuaclient.js:768:11)
    at C:\ProgramData\npmglobal\node_modules\node-red\node_modules\@node-red\runtime\lib\nodes\Node.js:214:26
    at Object.trigger (C:\ProgramData\npmglobal\node_modules\node-red\node_modules\@node-red\util\lib\hooks.js:166:13)
    at Node._emitInput (C:\ProgramData\npmglobal\node_modules\node-red\node_modules\@node-red\runtime\lib\nodes\Node.js:206:11)
    at Node.emit (C:\ProgramData\npmglobal\node_modules\node-red\node_modules\@node-red\runtime\lib\nodes\Node.js:190:25)
    at Node.receive (C:\ProgramData\npmglobal\node_modules\node-red\node_modules\@node-red\runtime\lib\nodes\Node.js:506:10)

```

After restart I am receiving these messages see log below:

> ```auto
> 21:57:15.150Z :client_session_impl :1210 ----------------> session Repaired, now redoing original transaction
> 21:58:15.141Z :client_session_impl :712 Transaction on Invalid Session ReadRequest serviceResult = BadSessionIdInvalid (0x80250000) isReconnecting?= false q= 0
> 21:58:15.141Z :client_session_impl :1196 attempt to recreate session to reperform a transaction ReadRequest
> 21:58:15.142Z :client_session_impl :1203 ----------------> Repairing Client Session as Server believes it is invalid now
> 21:58:15.171Z :client_session_impl :1210 ----------------> session Repaired, now redoing original transaction
> 21:59:15.141Z :client_session_impl :712 Transaction on Invalid Session ReadRequest serviceResult = BadSessionIdInvalid (0x80250000) isReconnecting?= false q= 0
> 21:59:15.149Z :client_session_impl :1196 attempt to recreate session to reperform a transaction ReadRequest
> 21:59:15.150Z :client_session_impl :1203 ----------------> Repairing Client Session as Server believes it is invalid now
> 21:59:15.175Z :client_session_impl :1210 ----------------> session Repaired, now redoing original transaction
> 22:00:15.158Z :client_session_impl :712 Transaction on Invalid Session ReadRequest serviceResult = BadSessionIdInvalid (0x80250000) isReconnecting?= false q= 0
> 22:00:15.158Z :client_session_impl :712 This warning occurred more than 100 times, no more warning will be logged for this context
> 22:00:15.158Z :client_session_impl :1196 attempt to recreate session to reperform a transaction ReadRequest
> 22:00:15.158Z :client_session_impl :1196 This warning occurred more than 100 times, no more warning will be logged for this context
> 22:00:15.159Z :client_session_impl :1203 ----------------> Repairing Client Session as Server believes it is invalid now
> 22:00:15.160Z :client_session_impl :1203 This warning occurred more than 100 times, no more warning will be logged for this context
> 22:00:15.184Z :client_session_impl :1210 ----------------> session Repaired, now redoing original transaction
> 22:00:15.184Z :client_session_impl :1210 This warning occurred more than 100 times, no more warning will be logged for this context
> 
> ```

Here are my specifications:

```auto
Node-RED version: v4.1.8

Node.js version: v24.15.0

Windows_NT 10.0.22631 x64 LE(Windows 11, 23H2

node-red-contrib-opcua 0.2.350

+-------------------------------------------------------------------------------------+

| Warning: |

| node-opcua-client-crawler module has been deprecated and is not maintained anymore. |

| Please use '@sterfive/crawler' instead. |

| '@sterfive/crawler' is available to the NodeOPCUA Subscription members |

+-------------------------------------------------------------------------------------+

PLC: Siemens SIMATIC S7-1500

```

Can you help me the way ho to find out the reason why it is crashing and how to fix it?

Many thanks for any piece of Advice.

Petr Duga

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 June 2026 05:34 UTC](https://discourse.nodered.org/t/problem-by-using-node-red-contrib-opcua-for-plc-backup/101182/2 "2026-06-04T05:34:10Z")

</div>

Hi. Your image is not great quality. Can you post the logs as text?

Additionally, you pasted the function code without putting it inside of a code block (see canned info below). I've tried editing your post but your function code is pretty much messed up due to not having it in a code block in the first place. Can you correct that?

Next, can you tell us what type of PLC make & model?

Other information that may be useful would be the node.js version you're running on?

* * *

### canned info

In order to make code readable and usable it is necessary to surround your code with three backticks (also known as a left quote or backquote `````)

````auto
``` 
   code goes here 
```

````

You can edit and correct your post by clicking the pencil ✏ icon.

See this post for more details - [How to share code or flow json](https://discourse.nodered.org/t/how-to-share-code-or-flow-json/506)

---

<div class="post-metadata">

**Author:** ![Petonius](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@Petonius](https://discourse.nodered.org/u/Petonius)\
**Post date:** [4 June 2026 09:06 UTC](https://discourse.nodered.org/t/problem-by-using-node-red-contrib-opcua-for-plc-backup/101182/3 "2026-06-04T09:06:45Z")

</div>

Hi,

thanks @Steve-Mcl for your comment. I tried to improve the form. and add some more details.

I am going to change the picture to text log, after my next testing. In log is expected somewhere the number and is received NaN. I will check my code one more time.

Thank you

Petr Duga

---

<div class="post-metadata">

**Author:** ![Petonius](https://avatars.discourse-cdn.com/v4/letter/p/6f9a4e/32.png) [@Petonius](https://discourse.nodered.org/u/Petonius)\
**Post date:** [4 June 2026 14:10 UTC](https://discourse.nodered.org/t/problem-by-using-node-red-contrib-opcua-for-plc-backup/101182/4 "2026-06-04T14:10:45Z")

</div>

'''

Hi there,

there was my mistake in definition of arr3[].

I missed one "" just behind the "9".

'''

Was:

```auto
9,"true",10,"true","",

```

Should be:

```auto
9,"true","",10,"true","",

```

'''

After correction the workflow worked without problems and I reuse it for backup other variables.

Hopefully this can help others by backup data from PLC using OPC UA.

Many thanks.

'''

Petr Duga

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [18 June 2026 14:10 UTC](https://discourse.nodered.org/t/problem-by-using-node-red-contrib-opcua-for-plc-backup/101182/5 "2026-06-18T14:10:53Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
