Hi
I am currently working on a way to make a hex buffer out of various hex stings.
A microcontroller (ESP32) will be using those hex values as values to compare an input with.
I want to keep the message over MQTT as small as possible. Eventually the size will be 50KB.
The following flow consists of:
-A working function where a few hexstrings will be converted to an integer.
-A not working function where node-red freezes completely... (Use at own risk).
I do not get why this makes it crash...
[{"id":"1b78ffdb.adbf5","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"1cfe95.33e3216c","type":"inject","z":"1b78ffdb.adbf5","name":"FREEZE","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"package\":{\"allowedTokens\":[\"ffffffff\",\"feffffff\",\"fdffffff\",\"f0ffff\",\"ffffffff\",\"0fffffff\",\"ffff\"]}}","payloadType":"json","x":120,"y":340,"wires":[["ea6f02c.7752b"]]},{"id":"ea6f02c.7752b","type":"function","z":"1b78ffdb.adbf5","name":"","func":"var arrayIndex = [];\nvar arrayDB = [];\n\nfor(var i = 0; i<msg.payload.package.allowedTokens.length; i++){\n \n if (msg.payload.package.allowedTokens[i].length % 2) {\n msg.payload.package.allowedTokens[i] = '0' + msg.payload.package.allowedTokens[i];\n }\n var index = 0;\n for(var j = 0; j<msg.payload.package.allowedTokens[i].length; j+2){\n var subStr = msg.payload.package.allowedTokens[i].substring(j, j + 2);\n arrayDB[j] = parseInt(subStr,16);\n index++;\n }\n arrayIndex[i] = index;\n \n}\n// return bufferAllowedTokens;\n// }\nmsg.payload=\"\";\nmsg.payload.request = {\"request\": \"Test\"};\nmsg.payload.package = {\"allowedTokens\": arrayDB};\nmsg.payload.package = {\"arrayIndex\": arrayIndex};\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":340,"wires":[["bfff5362.cab5b"]]},{"id":"bfff5362.cab5b","type":"debug","z":"1b78ffdb.adbf5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":340,"wires":[]},{"id":"9af8572.e34dea8","type":"function","z":"1b78ffdb.adbf5","name":"","func":"for(var i = 0; i<msg.payload.package.allowedTokens.length; i++){\n // while(msg.payload.package.allowedTokens[i].length != 16){\n \n // }\n msg.payload.package.allowedTokens[i] = parseInt(msg.payload.package.allowedTokens[i],16);\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":140,"wires":[["5ab00037.f7b44"]]},{"id":"48b697fe.837ee8","type":"inject","z":"1b78ffdb.adbf5","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"package\":{\"allowedTokens\":[\"049b26870ec9b92c\",\"c704a48b079c8db9\",\"d267e8f255b65fee\",\"66ca6022885a74e1\",\"3dce7df596f567a0\",\"64ab45796b1a83da\",\"dccf0b13c7dd9098\",\"8c3b38588c2ba11b\",\"aaab4873fe0c94df\",\"7ac8a016\",\"d9fe13b4\",\"03350f2a\"]}}","payloadType":"json","x":110,"y":140,"wires":[["9af8572.e34dea8"]]},{"id":"5ab00037.f7b44","type":"debug","z":"1b78ffdb.adbf5","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":140,"wires":[]},{"id":"5788ce3b.073eb","type":"comment","z":"1b78ffdb.adbf5","name":"Working without substring","info":"","x":150,"y":80,"wires":[]},{"id":"bd8f92a6.36318","type":"comment","z":"1b78ffdb.adbf5","name":"[FREEZES Node-Red] Not working with substring","info":"","x":220,"y":280,"wires":[]}]