Hi all,
i create a flow with a javascript code that convert a number to binary (6 numbers) and based on 1 or 0 poweron/poweroff 6 switches and wait 3 seconds for 64 cycles (2^6 possibilities) and then reset to 1
All works fine if i manually click on a inject. I create a loop connecting the delay to the js function and it start to work ok for about 5-6 loops and then it start to put random numbers blocking the nodered instance.
Someone can help me to solve?
This is the basic flow
[{"id":"15056c5e.4b8594","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"247a86f7.e101c2","type":"function","z":"15056c5e.4b8594","name":"","func":"var count = context.get('count')||1;\nvar i = context.get('i')||1;\nvar first = context.get('first')||1;\n\n\n//count = i * count;\nif ((count *2) > 62) {\n\ti += 2;\n\tif (i > 64) { i = 2; } //reset\n count = 1;\n\tcount = i * count;\n }\n\telse { \n\t if (first == 1) { \n\t count = 1; \n\t first = 2;\n\t } else { count = count * 2; }}\n\t\nvar res = count.toString(2).padStart(6,\"0\");\n\n// store the value back\t\ncontext.set('count',count);\ncontext.set('i',i);\ncontext.set('first',first);\n\n//LSB\n\nvar msg6 = { payload: res.substring(0, 1) };\nvar msg5 = { payload: res.substring(1, 2) };\nvar msg4 = { payload: res.substring(2, 3) };\nvar msg3 = { payload: res.substring(3, 4) };\nvar msg2 = { payload: res.substring(4, 5) };\nvar msg1 = { payload: res.substring(5, 6) };\n\nvar msgG = { payload: res };\n\nreturn [msg1,msg2,msg3,msg4,msg5,msg6,msgG];","outputs":7,"noerr":0,"x":330,"y":440,"wires":[["5398a974.0f0f98"],["ab5f303.1964f5"],["f12cbac.a0290c8"],["83dfed9d.4f9f8"],["9de792b9.6daf58"],["a9fc7d9.da658"],["f50acfae.30e2"]]},{"id":"25821ee9.c8df72","type":"inject","z":"15056c5e.4b8594","name":"TEST SWITCH - MANUAL MODE","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":620,"wires":[["247a86f7.e101c2"]]},{"id":"5398a974.0f0f98","type":"switch","z":"15056c5e.4b8594","name":"Switch1","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":340,"wires":[["a5ac7616.725e18"]]},{"id":"ab5f303.1964f5","type":"switch","z":"15056c5e.4b8594","name":"Switch2","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":420,"wires":[["a5ac7616.725e18"]]},{"id":"f12cbac.a0290c8","type":"switch","z":"15056c5e.4b8594","name":"Switch3","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":500,"wires":[["a5ac7616.725e18"]]},{"id":"83dfed9d.4f9f8","type":"switch","z":"15056c5e.4b8594","name":"Switch4","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":580,"wires":[["a5ac7616.725e18"]]},{"id":"9de792b9.6daf58","type":"switch","z":"15056c5e.4b8594","name":"Switch5","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":660,"wires":[["a5ac7616.725e18"]]},{"id":"a9fc7d9.da658","type":"switch","z":"15056c5e.4b8594","name":"Switch6","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":740,"wires":[["a5ac7616.725e18"]]},{"id":"f50acfae.30e2","type":"debug","z":"15056c5e.4b8594","name":"MSG_ALL","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":550,"y":840,"wires":[]},{"id":"a5ac7616.725e18","type":"delay","z":"15056c5e.4b8594","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":880,"y":420,"wires":[["247a86f7.e101c2"]]}]
Thanks to all