Hi all,
With help from ChatGPT I've created a function node that loops a subflow which reads the present value of a BACnet point. With my function node looping four times, a debug on the output of the subflow shows the four values in the debug window.
However I'm not having any success getting the four values to write into an array. ChatGPT gave me a basic function node takes a bunch of numbers, doubles them, then loads them into a second array which is stored in a flow variable:
// Sample array of numbers
let numbers = [1, 2, 3, 4, 5];
let results = [];
// Loop through the numbers array
for (let i = 0; i < numbers.length; i++) {
results.push(numbers[i] * 2); // Example operation: doubling each number
}
// Store the results in a flow variable
flow.set('double', results);
// Optionally, send the result as a message payload if you want to pass it on in the flow
msg.payload = results;
return null;
My function node contains this (mostly written by ChatGPT):
let results = flow.get('Current') || [];
// Loop through the numbers array
for (let i = 1501; i <= 1504; i++) {
node.send({instance: i});
results.push(msg.payload)
}
// Store the results in a flow variable
flow.set('Current', results);
// Optionally, send the result as a message payload if you want to pass it on in the flow
msg.payload = flow.get('Current');
return null;
The subflow takes the instance i and correctly spits out the present values for analog inputs 1501, 1502, 1503 and 1504. However the flow variable 'Current' in which I want to store those values ends up with what appear to be epoch time stamps in it.
[1738730646869,1738730646869,1738730646869,1738730646869,1738730771309,1738730771309,1738730771309,1738730771309]
Eight values too, not the four I'm generating.
Can anybody spot my problem and advise me?