Skip to content

Instantly share code, notes, and snippets.

@itarozzi
Created December 26, 2017 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save itarozzi/30d1fc9526fb6960f083710a91416a6e to your computer and use it in GitHub Desktop.
Save itarozzi/30d1fc9526fb6960f083710a91416a6e to your computer and use it in GitHub Desktop.
Esempio di realizzazione di un loop (FOR-DO) all'interno di nodered
[{"id":"fed25495.5b2798","type":"inject","z":"8057655f.a7bd08","name":"","topic":"","payload":"5","payloadType":"num","repeat":"","crontab":"","once":false,"x":103,"y":117,"wires":[["34f34e08.bde052"]]},{"id":"57b232ee.d7d5bc","type":"function","z":"8057655f.a7bd08","name":"Loop","func":"// Loop function\n\nvar cnt = flow.get('loop_count')||0;\n\ncnt--;\n\nflow.set('loop_count', cnt);\n\nif (cnt >= 0) {\n // repeat again\n return [ null, msg ];\n}\nelse {\n // loop end\n return [ msg, null ];\n}\n\n","outputs":"2","noerr":0,"x":385,"y":132,"wires":[["3818f3b3.d2efac"],["527c1e03.1c10d"]]},{"id":"c39bdb58.03bd38","type":"debug","z":"8057655f.a7bd08","name":"","active":true,"console":"false","complete":"false","x":1038,"y":100,"wires":[]},{"id":"d1f83628.430bb8","type":"debug","z":"8057655f.a7bd08","name":"","active":true,"console":"false","complete":"false","x":774,"y":142,"wires":[]},{"id":"34f34e08.bde052","type":"change","z":"8057655f.a7bd08","name":"init","rules":[{"t":"set","p":"loop_count","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":231,"y":118,"wires":[["57b232ee.d7d5bc"]]},{"id":"3818f3b3.d2efac","type":"change","z":"8057655f.a7bd08","name":"DONE","rules":[{"t":"set","p":"payload","pt":"msg","to":"DONE","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":560,"y":89,"wires":[["d1f83628.430bb8"]]},{"id":"527c1e03.1c10d","type":"change","z":"8057655f.a7bd08","name":"EXECUTE ","rules":[{"t":"set","p":"payload","pt":"msg","to":"EXECUTE","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":571,"y":141,"wires":[["d1f83628.430bb8","3c106c07.da7c34"]]},{"id":"3c106c07.da7c34","type":"delay","z":"8057655f.a7bd08","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":548,"y":231,"wires":[["57b232ee.d7d5bc"]]},{"id":"ee5addfd.eaaea","type":"inject","z":"8057655f.a7bd08","name":"","topic":"","payload":"5","payloadType":"num","repeat":"","crontab":"","once":false,"x":98,"y":369,"wires":[["725789ad.6f2e08"]]},{"id":"ed72896a.804fc8","type":"function","z":"8057655f.a7bd08","name":"Loop","func":"// Loop function\nvar cnt = msg.loop_count||0;\ncnt--;\n\nmsg.loop_count = cnt;\n\nif (cnt >= 0) {\n // repeat again\n return [ null, msg ];\n}\nelse {\n // loop end\n return [ msg, null ];\n}\n\n","outputs":"2","noerr":0,"x":408,"y":380,"wires":[["370cad9e.d07162"],["a94066bc.c57d58"]]},{"id":"90ed630.675d7a","type":"debug","z":"8057655f.a7bd08","name":"","active":true,"console":"false","complete":"false","x":759,"y":396,"wires":[]},{"id":"725789ad.6f2e08","type":"change","z":"8057655f.a7bd08","name":"init","rules":[{"t":"set","p":"loop_count","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":226,"y":370,"wires":[["ed72896a.804fc8"]]},{"id":"370cad9e.d07162","type":"change","z":"8057655f.a7bd08","name":"DONE","rules":[{"t":"set","p":"payload","pt":"msg","to":"DONE","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":555,"y":341,"wires":[["90ed630.675d7a"]]},{"id":"a94066bc.c57d58","type":"change","z":"8057655f.a7bd08","name":"EXECUTE ","rules":[{"t":"set","p":"payload","pt":"msg","to":"EXECUTE","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":566,"y":393,"wires":[["90ed630.675d7a","af8a0587.877ff8"]]},{"id":"af8a0587.877ff8","type":"delay","z":"8057655f.a7bd08","name":"","pauseType":"delay","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":543,"y":483,"wires":[["ed72896a.804fc8"]]},{"id":"138157eb.592ce8","type":"comment","z":"8057655f.a7bd08","name":"LOOP con variabili globali","info":"","x":172,"y":64,"wires":[]},{"id":"9bf8f48c.da6c18","type":"comment","z":"8057655f.a7bd08","name":"LOOP con counter nel messaggio","info":"","x":155,"y":312,"wires":[]}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment