Hi
var Zone = msg.payload;
var Value = '34:80:73:90:d9:82';
const xx=[];
var x;
var y;
var radius;
var color;
if (Value == Zone) {
if(!xx.includes(45)){
x = 45;
y = 70;
radius = 6;
color = '#7D6608';
xx.push(x);
}
if(!xx.includes(55)){
x = 55;
y = 70;
radius = 6;
color = '#7D6608';
xx.push(x);
}
if(!xx.includes(85)){
x = 85;
y = 70;
radius = 6;
color = '#7D6608';
xx.push(x);
}
}
else {
x = x;
y = y;
radius = radius;
color = 'red';
}
msg.lat = x
msg.long = y
msg.radius = radius
msg.color = color
return {
payload: [{
x: msg.lat,
y: msg.long,
radius: msg.radius,
color: msg.color
}]
}
In the above function, I am comparing two conditions.
First, if the incoming value and defined value are the same, it should send x and y values.
2nd when the function is executed. It should send the first set of values and store them in an array. When it is triggered a second time, it should compare whether the value x is present in the array. If it is, it should send the next set of values.
Help is needed !
[
{
"id": "ddbb8807e1dafec2",
"type": "inject",
"z": "35bc2aafbcc33d8e",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "34:80:73:90:d9:82",
"payloadType": "str",
"x": 190,
"y": 140,
"wires": [
[
"0b059a56507de4ae"
]
]
},
{
"id": "0b059a56507de4ae",
"type": "function",
"z": "35bc2aafbcc33d8e",
"name": "function 88",
"func": "var Zone = msg.payload;\nvar Value = '34:80:73:90:d9:82';\nconst xx=[];\n\nvar x;\nvar y;\nvar radius;\nvar color;\n\nif (Value == Zone) {\n if(!xx.includes(45)){\n x = 45;\n y = 70;\n radius = 6;\n color = '#7D6608';\n xx.push(x);\n }\n if(!xx.includes(55)){\n x = 55;\n y = 70;\n radius = 6;\n color = '#7D6608';\n xx.push(x);\n }\n if(!xx.includes(85)){\n x = 85;\n y = 70;\n radius = 6;\n color = '#7D6608';\n xx.push(x);\n }\n }\n else {\n x = x;\n y = y;\n radius = radius;\n color = 'red';\n }\n\nmsg.lat = x\nmsg.long = y\nmsg.radius = radius\nmsg.color = color\n\nreturn {\n payload: [{\n x: msg.lat,\n y: msg.long,\n radius: msg.radius,\n color: msg.color\n }]\n}\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 270,
"y": 180,
"wires": [
[
"226552e7f5101b02",
"6e9af15df22cc7a3"
]
]
},
{
"id": "6e9af15df22cc7a3",
"type": "debug",
"z": "35bc2aafbcc33d8e",
"name": "debug 84",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 480,
"y": 180,
"wires": []
}
]