Heatmap array shift

I have a .txt file which has an array of 10240 values to use for a heatmap (size: 16 x 16). My flow works just fine on the first inject after deploying it, but the heatmap seems to be moving one frame down (and one frame to the right) on subsequent injects using the repeat inject option. I suspect this is an issue with maybe a cache or buffer but I'm pretty new to the node.js language to diagnose further. I've added a couple screenshots (skipping some shots in between to exaggerate the issue) of the map with the values.

Using Node-RED 1.2.7 and the module in question is node-red-contrib-ui-heatmap (2.1.3)

1 2

[{"id":"e4f02345.29fe9","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"b7460f63.af1bf","type":"inject","z":"e4f02345.29fe9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"5","crontab":"","once":true,"onceDelay":"5","topic":"","payload":"true","payloadType":"bool","x":330,"y":400,"wires":[["6893dd8.4416324"]]},{"id":"6893dd8.4416324","type":"file in","z":"e4f02345.29fe9","name":"file input","filename":"C:\\Users\\User\\Desktop\\Project\\test2.txt","format":"lines","chunk":false,"sendError":false,"encoding":"none","x":460,"y":400,"wires":[["624d3bee.051ea4"]]},{"id":"624d3bee.051ea4","type":"function","z":"e4f02345.29fe9","name":"str2num","func":"msg.payload = Number(msg.payload);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":400,"wires":[["ae5c80d5.b7b7a"]]},{"id":"ae5c80d5.b7b7a","type":"join","z":"e4f02345.29fe9","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"256","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":730,"y":400,"wires":[["9b98ebbf.fe8798"]]},{"id":"40f27f0f.72e55","type":"ui_heat_map","z":"e4f02345.29fe9","group":"2e442781.0c5608","order":0,"width":"6","height":"6","name":"show heat map","rows":"16","columns":"16","minMax":true,"minimumValue":"0","maximumValue":"500","backgroundType":"color","backgroundColor":"#4929bc","radius":40,"opacity":"1","blur":"1","showValues":false,"gridType":"vals","valuesDecimals":"0","showLegend":false,"legendType":"none","legendDecimals":0,"legendCount":2,"x":1080,"y":440,"wires":[]},{"id":"3bf254f8.a0da8c","type":"debug","z":"e4f02345.29fe9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1070,"y":400,"wires":[]},{"id":"9b98ebbf.fe8798","type":"delay","z":"e4f02345.29fe9","name":"","pauseType":"rate","timeout":"1","timeoutUnits":"seconds","rate":"12","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":880,"y":400,"wires":[["3bf254f8.a0da8c","40f27f0f.72e55"]]},{"id":"2e442781.0c5608","type":"ui_group","name":"Heatmap","tab":"4779176.99cd2e8","order":1,"disp":true,"width":"6","collapse":true},{"id":"4779176.99cd2e8","type":"ui_tab","name":"Home","icon":"dashboard","disabled":false,"hidden":false}]

Is there a newline on the end of your file?

1 Like

Yup, you were right, there was! Getting rid of it fixed the issue. Thank you!

Could you elaborate on why the newline was causing this? Was the heatmap array one value short?

I would think it was keeping an extra value in the join node, so next time through it only took 255 values to send.

[edit]
You could add a check for empty values and not pass them on to join node, that way the newline would have been ignored.

There are many ways to read the file into an array, check these out, i add a time comparison check the time in seconds under the debug node.

[{"id":"b7460f63.af1bf","type":"inject","z":"e4f02345.29fe9","name":"","props":[{"p":"payload"},{"p":"time","v":"","vt":"date"}],"repeat":"","crontab":"","once":false,"onceDelay":"5","topic":"","payload":"true","payloadType":"bool","x":450,"y":360,"wires":[["6893dd8.4416324"]]},{"id":"6893dd8.4416324","type":"file in","z":"e4f02345.29fe9","name":"file input","filename":"C:\\Users\\User\\Desktop\\Project\\test2.txt","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":530,"y":400,"wires":[["f6f89080.08c808"]]},{"id":"f6f89080.08c808","type":"function","z":"e4f02345.29fe9","name":"","func":"msg.payload = msg.payload.split(/\\n/).reduce((a,v) => (v ? a.concat(Number(v)) : a),[]);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":690,"y":400,"wires":[["9b98ebbf.fe8798"]]},{"id":"9b98ebbf.fe8798","type":"delay","z":"e4f02345.29fe9","name":"","pauseType":"rate","timeout":"1","timeoutUnits":"seconds","rate":"12","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":880,"y":400,"wires":[["3bf254f8.a0da8c"]]},{"id":"3bf254f8.a0da8c","type":"debug","z":"e4f02345.29fe9","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"($millis()-time)/1000","statusType":"jsonata","x":1070,"y":400,"wires":[]},{"id":"ae5c80d5.b7b7a","type":"join","z":"e4f02345.29fe9","name":"","mode":"custom","build":"array","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","accumulate":false,"timeout":"","count":"256","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":750,"y":280,"wires":[["9b98ebbf.fe8798"]]},{"id":"624d3bee.051ea4","type":"function","z":"e4f02345.29fe9","name":"str2num","func":"msg.payload = Number(msg.payload);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":610,"y":280,"wires":[["ae5c80d5.b7b7a"]]},{"id":"17f0a253.6b68be","type":"file in","z":"e4f02345.29fe9","name":"file input","filename":"C:\\Users\\User\\Desktop\\Project\\test2.txt","format":"utf8","chunk":false,"sendError":false,"encoding":"none","x":630,"y":200,"wires":[["624d3bee.051ea4"]]},{"id":"c835d954.0cd2d","type":"inject","z":"e4f02345.29fe9","name":"","props":[{"p":"payload"},{"p":"time","v":"","vt":"date"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":470,"y":200,"wires":[["17f0a253.6b68be"]]}]
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.