BiancoRoyal / node-red-contrib-iiot-opcua

deprecated - very new developed by PLUS for Node-RED - https://plus4nodered.com
https://www.npmjs.com/package/node-red-contrib-iiot-opcua
BSD 3-Clause "New" or "Revised" License
34 stars 9 forks source link

Bug in BuildVariant (opcua-iiot-core.ts): Values like 0, 0.0, or false result in null (or NaN) values #190

Closed dei-p4i closed 1 year ago

dei-p4i commented 2 years ago

Which node-red-contrib-iiot-opcua version are you using?

4.0.9

What happened?

We encountered getting #NaN as values on our OPC UA Server, when using the write node, if the value was 0.0. Further testing showed that also 0 (for int types) and false (for boolean) resulted in null errors. Note: Before updating to 4.0.9 we used a 3.x.x version without that problem (don't remember exact version)

I found a probable problematic line of code in the package source: the if-test in the beginning of buildNewVariant in /src/core/opcua-iiot-core.ts:

  let variantValue: VariantOptions = {
    dataType: DataType.Null,
    value: null
  }
  // Possible bug location:
  // javascript interprets 0, 0.0 and false (or empty arrays or ...) here as false, so value stays "null"
  if (value.value)
    value = value.value

Server

OPCUA-IIoT-Flex-Server Node (Please attach AddressSpaceScript to the next section)

How can this be reproduced?

Zipped Demo with Flex-Server using (slightly modified) original addressSpace code: demo-iiot-opcua-zero-value-bug.json.zip

What did you expect to happen?

Value should be 0.0 (or 0 or false depending on used data type)

Other Information

No response

biancode commented 2 years ago

It would be good to have tests for this issue.

CW0815 commented 2 years ago

opc.tcp://milo.digitalpetri.com:62541/milo ns=2;s=CTT/Static/All Profiles/Scalar/Int16

Write Set value to 1 by inject (value is 1) Set value to 0 by inject ("Error: expecting a number NaN") Set value to "0" by inject (value is 0)

Read read 1 by inject (msg.payload.value[0].value is 1) read 0 by inject (msg.payload.value[0].value.value is 0)

biancode commented 2 years ago

We working on a version 4.1 - we found a lot issues after the TS merge, which are to be fixed soon.

CW0815 commented 1 year ago

same problem with version 4.1

opc.tcp://milo.digitalpetri.com:62541/milo ns=2;s=CTT/Static/All Profiles/Scalar/Int16

Write Set value to 1 by inject (value is 1) Set value to 0 by inject ("Error: expecting a number NaN") Set value to "0" by inject (value is 0)

Read read 1 by inject (msg.payload.value[0].value is 1) read 0 by inject (msg.payload.value[0].value.value is 0)

biancode commented 1 year ago

We did not work on that for now. Maybe we have it next week in our next release.

biancode commented 1 year ago

@JoelKrec we should include this as a test in the package.

biancode commented 1 year ago

v4.1.1 actual test - release soon

image
biancode commented 1 year ago

Test Flow to implement in e2e testings

image

TestFlowZeroValueBug.json.zip

CW0815 commented 1 year ago

v4.1.1 the value is null, but with "OPCUA-IIoT-Inject" + "function" the value is 0

msg.payload.nodetype = 'inject'; msg.payload.injectType = 'write'

msg.payload.valuesToWrite = []; msg.payload.valuesToWrite[0] = "0";

return msg;

Test_Zero_01 TestFlowZeroValueBug02.zip

biancode commented 1 year ago

@CW0815 give v4.1.2 a try

CW0815 commented 1 year ago

This works with v4.1.2

But with a Response between Read and helper, the output is different at 0 and 1.

Test_Zero_03

biancode commented 1 year ago

The response node is not working very well after the shift to TypeScript. See the TODO.md for more information.

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 60 days with no activity. It will be closed in 15 days, but can be saved by removing the stale label or commenting.