node-opcua / node-opcua

Unlocking the Full Potential of OPC UA with Typescript and NodeJS - http://node-opcua.github.io/
MIT License
1.49k stars 481 forks source link

Aggregation giving following Error: serviceResult = BadAggregateListMismatch (0x80d40000) #874

Closed shreeramk closed 4 years ago

shreeramk commented 4 years ago

Error: Error: serviceResult = BadAggregateListMismatch (0x80d40000)

Sample Code:

const nodeToRead = [{nodeId: "ns=6;s=2:\\\\osipiserver\\Generator.ABC"}, {nodeId: "ns=6;s=2:\\\\osipiserver\\Generator.CDE"}];

        the_session.readAggregateValue(nodeToRead, "2017-07-31T17:45:00.000Z", "2017-08-03T00:45:00.000Z", 2342, 3600000 , function(err, dataValues, diagnostics) {
            if (err)
                console.log("Error: ", err)
            else {
                console.log('No. of Nodes to be read: ', dataValues.length)
                for (let j = 0; j < dataValues.length; j++) {
                    if (dataValues[j].historyData)
                        console.log("No. of aggregated records fetchted for tag - ", nodeToRead[j], ": ", dataValues[j].historyData.dataValues.length)
                    else
                        console.log(dataValues[j])
                }
            }
        });
erossignon commented 4 years ago

There is not enough information to understand the issue and reproduce it, I am afraid, please fill the form.

mikakaraila commented 4 years ago

Or call parameter aggregate function is just wrong? Value 2342 should be 'Average' or some other aggregate.

const dataValues = await session.readAggregateValue(
        { nodeId: "ns=5;s=Simulation Examples.Functions.Sine1" },
        "2015-06-10T09:00:00.000Z",
        "2015-06-10T09:01:00.000Z", 'Average', 3600000);
shreeramk commented 4 years ago

@erossignon On running the sample code that I mentioned above(Get Aggregate(Average) for two tags between a date range), then I m getting an error which says:

Error: Error: serviceResult = BadAggregateListMismatch (0x80d40000)

Is the full call stack required here?

erossignon commented 4 years ago

The error that you see there BadAggregateListMismatch is generated by the remote server.

@shreeramk the missing information is about the server

I guess that you are using javascript and not typescript, therefore there are some type mismatch in passing argument to the method that cannot be detected. Strictly speaking the signature of the readAggregateValue method is :


    public async readAggregateValue(
        nodesToRead: HistoryReadValueIdOptions[],
        startTime: DateTime,
        endTime: DateTime,
        aggregateFn: AggregateFunction,
        processingInterval: number
) : Promise<HistoryReadResult[]>;

therefore the correct use should be:

const dataValues = await session.readAggregateValue(
        { nodeId: "ns=5;s=Simulation Examples.Functions.Sine1" },
        new Date("2015-06-10T09:00:00.000Z"),
        new Date("2015-06-10T09:01:00.000Z"), 
       AggregateFunction.Average, 36000);

Note: I realize the sample provided in the code is wrong ... this need fixing

erossignon commented 4 years ago

comment fixed in 77d46dd1d7062a45b50e1fba6a82f24c04d9374f

erossignon commented 4 years ago

Comment fix available in 2.19.0

@shreeramk please confirm that this helped

shreeramk commented 4 years ago

UA Tunneller: Matrikon OPC node-opcua: 2.14.0 and 2.19.0 Using Javascript.

Summary: If I try to get aggregated data for one nodeId, it works fine. _const nodeToRead = [{nodeId: "ns=6;s=2:\\osipiserver\Generator.ACTIVEPOWER"}];

But when I try to get aggregated data for more than one nodeId then below error is thrown Error: Error: serviceResult = BadAggregateListMismatch (0x80d40000)

_const nodeToRead = [{nodeId: "ns=6;s=2:\\osipiserver\Generator.UNIT4_ACTIVE_POWER"},{nodeId: "ns=6;s=2:\\osipiserver\Generator.GEN_CORE_TEMP3"},];

erossignon commented 4 years ago

Ok. I suggest you contact Matrikon support about it. This error is raised by the server itself.

erossignon commented 4 years ago

@shreeramk

*BadAggregateListMismatch means The requested number of Aggregates does not match the requested number of NodeIds

We need to add the ability to pass an arry of AggregateFunctions when mutilple nodeId are specified.

const dataValues = await session.readAggregateValue(
       [
          { nodeId: "ns=5;s=Simulation Examples.Functions.Sine1" },
          { nodeId: "ns=5;s=Simulation Examples.Functions.Sine2" }
      ],
        new Date("2015-06-10T09:00:00.000Z"),
        new Date("2015-06-10T09:01:00.000Z"), 
      [
              AggregateFunction.Average, 
              AggregateFunction.Average
      ],
      36000);
shreeramk commented 4 years ago

@erossignon Yes agreed.

shreeramk commented 4 years ago

@erossignon can i create a pull request for this? Or if you have already made the changes for same, then if you can merge & release it?

erossignon commented 4 years ago

@shreeramk , yes, sure! you're welcome, I haven't made the change yet, so go first.

erossignon commented 4 years ago

@shreeramk thanks for your contribution, your enhancement is now available in node-opcua@2.22.0