Whats a good way to repeat an incoming message?

i currently have some buttons in other software which are sending messages to Node Red.. when i press a button down it sends one message and when i release the button it sends a different message.. for example i press a button and it sends the message "0302" and the button release sends "0303".. each message is sent only once.. the button pressed message can vary (when pressing different buttons) but the button release message is always the same..

would anyone have a suggestion for a simple way to make the button pressed message (0302) repeat (at a rapid intervals which i can set) and then stop repeating when the button release (0303) occurs ? I currently have a goofy method i made to try and do this but it doesnt always work.

Will the trigger node not do what you want?
e.g

[{"id":"8f5f0338.c2023","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"button1","payload":"0302","payloadType":"str","x":110,"y":2980,"wires":[["729adff.1b1c7a"]]},{"id":"729adff.1b1c7a","type":"trigger","z":"bf9e1e33.030598","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"-1","extend":false,"overrideDelay":false,"units":"s","reset":"0303","bytopic":"topic","topic":"topic","outputs":1,"x":310,"y":3000,"wires":[["431ad9b5.9fed08"]]},{"id":"f462b308.c16e4","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"button1","payload":"0303","payloadType":"str","x":110,"y":3040,"wires":[["729adff.1b1c7a"]]},{"id":"431ad9b5.9fed08","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":3000,"wires":[]}]

Have a look at the resend node node-red-contrib-msg-resend (node) - Node-RED

sorry i forgot to mention that i also need the "0303" button released message to be passed once as it stops.. so detect 0302 while the button is pressed and continue to repeat that message indefinitely, then when button is released detect 0303, pass that message though once then stop..

otherwise the trigger node does what i need without anything extra but passing 0303 once is the part im bit stuck on finding a good solution to.. ?

Apart from "(at rapid intervals which I can set)" this seems to work:
EDIT - But ElCid's flow is much better!

[{"id":"5889a65712ffaf93","type":"inject","z":"ac631a6e.90e038","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0303","payloadType":"str","x":90,"y":800,"wires":[["9a295254d9fdccc6","4785aad0c0a9cf7e"]]},{"id":"8f14e6d56754a714","type":"inject","z":"ac631a6e.90e038","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0302","payloadType":"str","x":90,"y":740,"wires":[["9a295254d9fdccc6"]]},{"id":"9a295254d9fdccc6","type":"trigger","z":"ac631a6e.90e038","name":"","op1":"","op2":"","op1type":"pay","op2type":"payl","duration":"500","extend":false,"overrideDelay":true,"units":"ms","reset":"0303","bytopic":"all","topic":"topic","outputs":2,"x":340,"y":740,"wires":[["4785aad0c0a9cf7e"],["1639bec68c5b5dab"]]},{"id":"4785aad0c0a9cf7e","type":"debug","z":"ac631a6e.90e038","name":"debug 38","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":800,"wires":[]},{"id":"1639bec68c5b5dab","type":"junction","z":"ac631a6e.90e038","x":340,"y":780,"wires":[["9a295254d9fdccc6"]]}]

And adding in a variable repeat frequency:

[{"id":"3beda683b89b588f","type":"inject","z":"ac631a6e.90e038","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0302","payloadType":"str","x":90,"y":500,"wires":[["3527b67b5432f5ea"]]},{"id":"0bb6b62878a2ec74","type":"inject","z":"ac631a6e.90e038","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0303","payloadType":"str","x":90,"y":420,"wires":[["7370d7d76fb22747","f5fba0f2d85ffa62"]]},{"id":"f5fba0f2d85ffa62","type":"debug","z":"ac631a6e.90e038","name":"debug 37","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":600,"y":420,"wires":[]},{"id":"7370d7d76fb22747","type":"trigger","z":"ac631a6e.90e038","name":"","op1":"","op2":"","op1type":"pay","op2type":"payl","duration":"500","extend":false,"overrideDelay":true,"units":"ms","reset":"0303","bytopic":"all","topic":"topic","outputs":2,"x":400,"y":440,"wires":[["f5fba0f2d85ffa62"],["3527b67b5432f5ea"]]},{"id":"3527b67b5432f5ea","type":"change","z":"ac631a6e.90e038","name":"msg.delay = flow.delay","rules":[{"t":"set","p":"delay","pt":"msg","to":"delay","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":400,"y":500,"wires":[["7370d7d76fb22747"]]},{"id":"88da8c30f9e60aca","type":"inject","z":"ac631a6e.90e038","name":"delay 2 sec","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"2000","payloadType":"num","x":110,"y":640,"wires":[["78ee2f72d6c7f40a"]]},{"id":"8dc6df4db31954f1","type":"inject","z":"ac631a6e.90e038","name":"delay  1sec","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1000","payloadType":"num","x":100,"y":600,"wires":[["78ee2f72d6c7f40a"]]},{"id":"78ee2f72d6c7f40a","type":"change","z":"ac631a6e.90e038","name":"","rules":[{"t":"set","p":"delay","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":600,"wires":[[]]},{"id":"cec786876da5fc15","type":"inject","z":"ac631a6e.90e038","name":"delay 05s default","props":[{"p":"payload"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"500","payloadType":"num","x":130,"y":560,"wires":[["78ee2f72d6c7f40a"]]}]

thanks all for the ideas... jbudd.. your flow works nicely, for some reason i didnt think to just send the 0303 direct to debug with 0303 stopping the trigger at the same time.. seems obvious now i see it :slight_smile: thanks..

1 Like

Then add a switch node to pass the "0303" value around the trigger
e.g.

[{"id":"8f5f0338.c2023","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"button1","payload":"0302","payloadType":"str","x":110,"y":2980,"wires":[["729adff.1b1c7a","d4725167.b7d2b"]]},{"id":"729adff.1b1c7a","type":"trigger","z":"bf9e1e33.030598","name":"","op1":"","op2":"0","op1type":"pay","op2type":"str","duration":"-1","extend":false,"overrideDelay":false,"units":"s","reset":"0303","bytopic":"topic","topic":"topic","outputs":1,"x":310,"y":3000,"wires":[["431ad9b5.9fed08"]]},{"id":"d4725167.b7d2b","type":"switch","z":"bf9e1e33.030598","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0303","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":300,"y":3060,"wires":[["431ad9b5.9fed08"]]},{"id":"f462b308.c16e4","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"button1","payload":"0303","payloadType":"str","x":110,"y":3040,"wires":[["729adff.1b1c7a","d4725167.b7d2b"]]},{"id":"431ad9b5.9fed08","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":520,"y":3000,"wires":[]}]

You can not pass the payload direct if coming from same node as all "0302" will be passed to, you need to filter out the "0302" values.

awesome, appreciate the help..

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