Hi, guys
Just come across something strange. Could anyone give me some guides? Thanks heaps your time in advance.
Problem: I set two flow variables. When I assign value to one of the variables, another one get the same value assigned.
This text will be hiddenI use function: change data format to create flow variable: dataFromFirebaseFormated. Then I use dataFromFirebaseFormated to create another flow variable: sensorData. When I use function: store data to store data to variable: sensorData, the same value is stored at variable: dataFromFirebaseFormated. Show as annotation below
function: change data format
// data of card-allocation from firebase
let dataFromFirebase = JSON.parse(msg.payload);
let dataFromFirebaseFormated = flow.get('dataFromFirebaseFormated') || [];
// 1. take each value from variable dataFromFirebase
for (let x in dataFromFirebase) {
dataFromFirebaseFormated.push(dataFromFirebase[x]);
}
// 2. change format of mac from 'F09AC0BBA5E8' to [ 'F0', '9A', 'C0', 'BB', 'A5', 'E8' ]
dataFromFirebaseFormated.forEach(function(value) {
value.mac = value.mac.match(/.{1,2}/g);
});
// 3. change format of mac from [ 'F0', '9A', 'C0', 'BB', 'A5', 'E8' ] to [240, 154, 192, 187, 165, 232]
dataFromFirebaseFormated.forEach(function(value) {
value.mac.forEach(function(value2, index) {
value.mac[index] = parseInt(value2, 16);
value.anchor = [];
value.presence = [];
value.panic = 0;
value.date = 0;
});
});
flow.set('dataFromFirebaseFormated', dataFromFirebaseFormated);
msg.payload = dataFromFirebaseFormated;
return msg;
function: store data
// data of card-allocation from firebase
let dataFromFirebase = JSON.parse(msg.payload);
let dataFromFirebaseFormated = flow.get('dataFromFirebaseFormated') || [];
// 1. take each value from variable dataFromFirebase
for (let x in dataFromFirebase) {
dataFromFirebaseFormated.push(dataFromFirebase[x]);
}
// 2. change format of mac from 'F09AC0BBA5E8' to [ 'F0', '9A', 'C0', 'BB', 'A5', 'E8' ]
dataFromFirebaseFormated.forEach(function(value) {
value.mac = value.mac.match(/.{1,2}/g);
});
// 3. change format of mac from [ 'F0', '9A', 'C0', 'BB', 'A5', 'E8' ] to [240, 154, 192, 187, 165, 232]
dataFromFirebaseFormated.forEach(function(value) {
value.mac.forEach(function(value2, index) {
value.mac[index] = parseInt(value2, 16);
value.anchor = [];
value.presence = [];
value.panic = 0;
value.date = 0;
});
});
flow.set('dataFromFirebaseFormated', dataFromFirebaseFormated);
msg.payload = dataFromFirebaseFormated;
return msg;
node info:
18 Feb 23:21:20 - [info] Node-RED version: v1.0.3
18 Feb 23:21:20 - [info] Node.js version: v10.19.0