Hello, I created a dashboard where i can change the values of the variables in the function node. However I am getting an error when i deploy it stating that the variables are not defined. And also there is no change even when i change values in the dashboard. Can someone please help me out with it? I have shared the flow below.
[{"id":"7149cb47.db2534","type":"function","z":"869769d1.0b9f98","name":"Calculate average","func":"data=flow.get("data") || {};\nif (data.FIELD_WIDTH===undefined)\n var FIELD_WIDTH=100;\nelse\n var FIELD_WIDTH=parseInt(data.FIELD_WIDTH);\n\n\nif (data.FIELD_HEIGHT ===undefined)\n var FIELD_HEIGHT =100;\nelse\n var FIELD_HEIGHT =parseInt(data.FIELD_HEIGHT);\n \nif (data.FIELD_HORIZONTAL ===undefined)\n var FIELD_HORIZONTAL = 6;\nelse\n var FIELD_HORIZONTAL =parseInt(data.FIELD_HORIZONTAL); \n \nif (data.FIELD_VERTICAL ===undefined)\n var FIELD_VERTICAL = 20;\nelse\n var FIELD_VERTICAL =parseInt(data.FIELD_VERTICAL); \n \nmsg.payload ="FIELD_WIDTH ="+FIELD_WIDTH +" FIELD_HEIGHT ="+FIELD_HEIGHT+"FIELD_HORIZONTAL ="+FIELD_HORIZONTAL+"FIELD_VERTICAL ="+FIELD_VERTICAL;\nnode.log(msg.payload);\n//////////////////////////////\n\n\n\n\nconst inputArray = new Array (msg.payload.length);\n for (var n = 0 ; n < inputArray.length ; n++) {\n inputArray[n] = Object.values(msg.payload[n]);\n }\n\n // width and height of heating fields in pixels\n // dependant on distance between camera and object\n\n //const FIELD_WIDTH = 100;// 100;\n //const FIELD_HEIGTH = 100;// 100;\n \n\n // Width resolution of Images\n\n const RES_WIDTH = 100;// 100;\n\n // # of heating fields to calculate\n\n //const FIELDS_HORIZONTAL = 6;// 6;\n\n // because of zig-zag recording of camera 1 to generate same layouts.\n\n //const FIELDS_VERTICAL = 20;// 20;\n\n // first field starts half the field amount in length from middle of the image.\n\n // const HEATING_FIELD_START_HORIZONTAL = RES_WIDTH/2 - FIELDS_HORIZONTAL/2 * FIELD_WIDTH;\n const HEATING_FIELD_START_HORIZONTAL = 0;\n\n // Detect start of Fields// emperic values maybe?\n\n var HEATING_FIELD_START_DETECTION = detectStartHeating(inputArray);\n var HEATING_FIELD_END_DETECTION = detectEndHeating(inputArray);\n // var HEATING_FIELD_START_VERTICAL = (HEATING_FIELD_END_DETECTION - HEATING_FIELD_START_DETECTION )/ 2 + HEATING_FIELD_START_DETECTION - FIELDS_VERTICAL/2 * FIELD_HEIGTH;\n var HEATING_FIELD_START_VERTICAL = 0;\n\n // Creating an empty output Array with the set no fields\n\n var outputArray = new Array (FIELDS_VERTICAL);\n for (var k = 0 ; k< outputArray.length ; k++) {\n outputArray[k] = new Array (FIELDS_HORIZONTAL);\n for ( var l = 0; l< outputArray[k].length; l++) {\n outputArray[k][l] = 0;\n }\n }\n\n var tmp2 = 0;\n\n // loop through the fields\n\n for (var v = 0 ; v < FIELDS_VERTICAL ; v++) {\n for ( var h = 0; h < FIELDS_HORIZONTAL ; h++) {\n \n //calculate median of each field\n var tmp = 0 ;\n for ( var y = HEATING_FIELD_START_VERTICAL + v * FIELD_HEIGTH ; y < HEATING_FIELD_START_VERTICAL + v * FIELD_HEIGTH + FIELD_HEIGTH; y++) {\n for (var x = HEATING_FIELD_START_HORIZONTAL + h * FIELD_WIDTH; x < HEATING_FIELD_START_HORIZONTAL + h * FIELD_WIDTH + FIELD_WIDTH; x++) {\n tmp += parseFloat(inputArray[y]);\n }\n }\n \n // round to 2 decimals\n tmp = tmp / (FIELD_WIDTH * FIELD_HEIGTH)\n \n // no of decimal digits\n \n tmp = Math.round(tmp);\n outputArray[v][h] = tmp;\n\t\t}\n }\n \n // Create an empty array to insert the data\n // The desired output has 7 rows\n var newOutput = new Array (7);\n for (var k = 0 ; k< newOutput.length ; k++) {\n // Every row contains as much elements as the total number of fields\n newOutput[k] = new Array (FIELDS_HORIZONTAL * FIELDS_VERTICAL);\n for ( var l = 0; l< newOutput[k].length; l++) {\n newOutput[k][l] = 0;\n }\n }\n\n // Map the current result to the format desired\n // 7 rows were\n // row0 PixelName\n // row1 Width\n // row2 Height\n // row3 X\n // row4 Y\n // row5 Average\n // row6 Consecutive pixel name\n let firstRowIndex = 0;\n for (let rowIndex = 0; rowIndex < outputArray.length; rowIndex++) {\n const row = outputArray[rowIndex];\n for (let colIndex = 0; colIndex < row.length; colIndex++) {\n const col = row[colIndex];\n // Determine the name\n const pixelName = ${getLettherForRowNumber(rowIndex)}${colIndex}
;\n newOutput[0][firstRowIndex] = pixelName;\n newOutput[1][firstRowIndex] = FIELD_WIDTH ; // Width\n newOutput[2][firstRowIndex] = FIELD_HEIGTH; // Height\n newOutput[3][firstRowIndex] = colIndex * FIELD_WIDTH; // X\n newOutput[4][firstRowIndex] = rowIndex * FIELD_HEIGTH; // Y\n newOutput[5][firstRowIndex] = col; // Average\n // Determine the name 2\n const pixelName2 = a${firstRowIndex}
;\n newOutput[6][firstRowIndex] = pixelName2;\n firstRowIndex++;\n }\n }\n\t\n\tmsg.payload = newOutput;\n\t\n return msg;\n\n\t\nfunction detectStartHeating(inputArray) {\n\t \n\t// Haet difference from cool row to first heated row, how much hotter does the first heated row to be ?\n \n const THRESHOLD = 5;\n\n var hotRow = 0 ;\n var currentRowAverage = calcRowAverage(inputArray, hotRow);\n hotRow++;\n \n var nextRowAverage = calcRowAverage(inputArray,hotRow);\n while( currentRowAverage + THRESHOLD > nextRowAverage && currentRowAverage > -1 && nextRowAverage > -1) {\n\n currentRowAverage = nextRowAverage;\n hotRow++;\n nextRowAverage = calcRowAverage(inputArray,hotRow);\n }\n if (nextRowAverage == -1 || currentRowAverage == -1) {\n return 0;\n } else {\n return hotRow;\n }\n }\n\nfunction detectEndHeating(inputArray) {\n // heat difference from cool row to first heated row , how much hotter does the first heated row have to on average?\n \n const THRESHOLD = 40;\n var hotRow = inputArray.length - 1;\n var currentRowAverage = calcRowAverage(inputArray, hotRow);\n hotRow--;\n\n var prevRowAverage = calcRowAverage(inputArray,hotRow);\n\n while ( currentRowAverage + THRESHOLD > prevRowAverage && currentRowAverage > -1 && prevRowAverage > -1 && hotRow>0) {\n currentRowAverage = prevRowAverage;\n hotRow--;\n prevRowAverage = calcRowAverage(inputArray,hotRow);\n \n }\n if( prevRowAverage == -2 || currentRowAverage == -1) {\n return 0 ;\n }\n\n else\n {\n return hotRow;\n }\n }\n \nfunction calcRowAverage(inputArray,row) {\n var res = 0;\n if (inputArray.length < row) {\n return -1;\n }\n\n\n for (var g = 0; g< inputArray[row].length; g++) {\n res += inputArray[row][g];\n }\n return res/inputArray[row].length;\n}\t \n\nfunction getLettherForRowNumber(rowNumber) {\n // ASCII code for 'a' is 97, 122 for 'z'\n if (rowNumber < 26) {\n return String.fromCharCode(97 + rowNumber);\n } else {\n const asciiFirstLetter = Math.round(rowNumber / 25) - 1;\n const mod = rowNumber % 25 - 1;\n const firstLetter = String.fromCharCode(97 + asciiFirstLetter);\n const secondLetter = String.fromCharCode(97 + mod);\n return ${firstLetter}${secondLetter}
;\n }\n}\n","outputs":1,"noerr":0,"x":730,"y":260,"wires":[["261a99d3.e937d6"]]}]