Inject first message then block

Hello, I use an inject node to send a message automatically at regular interval.
My problem is that I want to let it passe the first message and then block (and unblock with conditions).
I have the solution to block and unblock but I don't know how it's possible to check that is the first message.
Do you have any solution ? Thank you :slight_smile:

The inject node can be set to only inject once at start. Or is that not what you want ?

Mmmh I think I've explained it wrong !
I want to inject a message every 5 seconds but I want only the first message to go through and then with a function I block it from being sent until a condition I have chosen unblocks it (to do this I have used a function node).
Basically I inject at regular intervals so that when the function unblocks the injection still works (that's why I don't use this inject node function).
Tell me if it's not clear or if it's better if I share my flow.

And then when it is unblocked it only sends one more ? or just repeats until something else blocks it ?

Both haha, it send one more and normally my function block it just after.

Is what you are injecting a constant value ?

Yes, I inject a msg.payload and a msg.topic (their values is "test").
I give you the flow if you want to see it.

[{"id":"cedf6ac1.bc7a48","type":"tab","label":"Request/Reponse co m1","disabled":false,"info":""},{"id":"a4a9d05f.526ca","type":"change","z":"cedf6ac1.bc7a48","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"test","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"ok","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":240,"wires":[["975d0b82.0e44f8","2083744b.582adc"]]},{"id":"38df4bb3.be5f44","type":"sms in","z":"cedf6ac1.bc7a48","name":"Response M1","x":150,"y":240,"wires":[["a4a9d05f.526ca","93de144a.fe6e88"]]},{"id":"dc6b5db.bc5a4a","type":"inject","z":"cedf6ac1.bc7a48","name":"test","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"5","crontab":"","once":true,"onceDelay":"5","topic":"test","payload":"test","payloadType":"str","x":370,"y":60,"wires":[["deb1ae1f.3470e","2083744b.582adc"]]},{"id":"4a4c4609.cf3818","type":"sms out","z":"cedf6ac1.bc7a48","name":"M1","number":"0777003752","x":890,"y":180,"wires":[]},{"id":"2083744b.582adc","type":"function","z":"cedf6ac1.bc7a48","name":"envoie/non envoie","func":"/* Partie de la fonction permetant de bloquer l'envoie automatique de message */\nvar block = context.get(\"block\") || false;\n\nif (msg.topic == \"ok\") {\n    block = false;\n    node.status({});//clear status\n} else if (msg.topic == \"test\") {\n    block = true;\n    node.status({fill:\"red\",shape:\"ring\",text:\"blocked\"});\n}\n\ncontext.set(\"block\", block);\n\nif(block) return null; //halt the flow\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":630,"y":180,"wires":[["4a4c4609.cf3818"]],"info":"Fonction permettant de détecter si l'acquittement a bien été fait par la première ou la deuxième personne d'astreinte dans le temps impartit.\n    - Si oui : les messages ne sont plus envoyé, sauf si changement d'état.\n    - Si non : les messages continuent d'être envoyé."},{"id":"975d0b82.0e44f8","type":"debug","z":"cedf6ac1.bc7a48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":340,"wires":[]},{"id":"deb1ae1f.3470e","type":"debug","z":"cedf6ac1.bc7a48","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":60,"wires":[]},{"id":"dffd4679.fa8ae8","type":"debug","z":"cedf6ac1.bc7a48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":340,"wires":[]},{"id":"93de144a.fe6e88","type":"debug","z":"cedf6ac1.bc7a48","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":340,"y":340,"wires":[]}]

OK - so that seems to work for me... or at least as far as you have described it... the top inject sets up the block - then the other unblocks it and shortly after the repeat on the top re-blocks it ?

Is the problem that while unblocked the lower (unblock) path can send several messages ? - but they are all unblock ones so will unblock it whatever ... or... not sure what I'm missing ??

The problem is that the inject is useless here because it doesn't send anything, it just allows the function to be blocked, but I would like the first message to go out BEFORE the function is blocked.
I don't want it to be used only to block the function permanently, but to send a first message, then receive one, send one back, etc.

I would use a rbe node instead and use msg.reset to unblock it...

[{"id":"a4a9d05f.526ca","type":"change","z":"cedf6ac1.bc7a48","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"test","tot":"str"},{"t":"set","p":"topic","pt":"msg","to":"ok","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":240,"wires":[["975d0b82.0e44f8","2083744b.582adc"]]},{"id":"dc6b5db.bc5a4a","type":"inject","z":"cedf6ac1.bc7a48","name":"test","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"5","crontab":"","once":true,"onceDelay":"1","topic":"test","payload":"test","payloadType":"str","x":370,"y":60,"wires":[["deb1ae1f.3470e","2083744b.582adc","bd21c004.493b1"]]},{"id":"2083744b.582adc","type":"function","z":"cedf6ac1.bc7a48","name":"envoie/non envoie","func":"/* Partie de la fonction permetant de bloquer l'envoie automatique de message */\nvar block = context.get(\"block\") || false;\n\nif (msg.topic == \"ok\") {\n    block = false;\n    node.status({});//clear status\n} else if (msg.topic == \"test\") {\n    block = true;\n    node.status({fill:\"red\",shape:\"ring\",text:\"blocked\"});\n}\n\ncontext.set(\"block\", block);\n\nif(block) return null; //halt the flow\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":630,"y":180,"wires":[["dffd4679.fa8ae8"]],"info":"Fonction permettant de détecter si l'acquittement a bien été fait par la première ou la deuxième personne d'astreinte dans le temps impartit.\n    - Si oui : les messages ne sont plus envoyé, sauf si changement d'état.\n    - Si non : les messages continuent d'être envoyé."},{"id":"975d0b82.0e44f8","type":"debug","z":"cedf6ac1.bc7a48","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":610,"y":260,"wires":[]},{"id":"deb1ae1f.3470e","type":"debug","z":"cedf6ac1.bc7a48","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":60,"wires":[]},{"id":"dffd4679.fa8ae8","type":"debug","z":"cedf6ac1.bc7a48","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":850,"y":180,"wires":[]},{"id":"baaabcb0.9bccb","type":"inject","z":"cedf6ac1.bc7a48","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":170,"y":200,"wires":[["a4a9d05f.526ca","bb8803a8.91d7"]]},{"id":"bd21c004.493b1","type":"rbe","z":"cedf6ac1.bc7a48","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":false,"property":"payload","topi":"topic","x":590,"y":400,"wires":[["54e7e873.bbeca8"]]},{"id":"54e7e873.bbeca8","type":"debug","z":"cedf6ac1.bc7a48","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":770,"y":400,"wires":[]},{"id":"bb8803a8.91d7","type":"change","z":"cedf6ac1.bc7a48","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":400,"wires":[["bd21c004.493b1"]]}]

Ok but the stream doesn't work (or doesn't do what I want it to do, it's ultimately the same problem), and the rbe node isn't connected to anything related to the sms out node so I don't understand what you're trying to do (and I'm really new to this language so it's taking me a while to understand).

Is this different to your other topic where you wanted to block / unblock?

Yes it's different, it's not the same flow and purpose...
I'm using the function in this topic (because I need to block a message) but it's not the same as what I need to do.
In the other topic, it is to acknowledge a warning that was sent by a modbus and here it is a communication between two GSM modules.

I don't have your sms nodes so was just using an inject as the in and the debug as the out...
But I really don't understand exactly what you want now..

The RBE one sends the first timed inject message "test":"test" - then blocks.... then when the other inject is clicked (to simulate and incoming sms) - it sends msg.reset that unblocks the rbe - and the next timed inject then sends "test":"test" again, and then blocks again... what is wrong with that ?

Okay, I understood that you didn't have the in and out sms. But there is still the same problem of: the first message doesn't go out, and when I send a message (from my laptop on the module) it answers twice (and yes from the rbe node and from the function...).
For me the RBE does not send anything at all, and the sending of messages is not timed, both are sent at the same time.

Are you sure that's not just a timing issue with the sms ? it certainly does send the first "test":"test" message out...
Here it is tidied up a bit

[{"id":"dc6b5db.bc5a4a","type":"inject","z":"ba9351cf.2e3e1","name":"test","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"5","crontab":"","once":false,"onceDelay":"1","topic":"test","payload":"test","payloadType":"str","x":350,"y":1280,"wires":[["deb1ae1f.3470e","bd21c004.493b1"]]},{"id":"deb1ae1f.3470e","type":"debug","z":"ba9351cf.2e3e1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":690,"y":1280,"wires":[]},{"id":"baaabcb0.9bccb","type":"inject","z":"ba9351cf.2e3e1","name":"SMS in node dummy","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":1420,"wires":[["bb8803a8.91d7"]]},{"id":"bd21c004.493b1","type":"rbe","z":"ba9351cf.2e3e1","name":"","func":"rbe","gap":"","start":"","inout":"out","septopics":false,"property":"payload","x":610,"y":1380,"wires":[["54e7e873.bbeca8"]]},{"id":"54e7e873.bbeca8","type":"debug","z":"ba9351cf.2e3e1","name":"SMS out node dummy","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":800,"y":1420,"wires":[]},{"id":"bb8803a8.91d7","type":"change","z":"ba9351cf.2e3e1","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":1380,"wires":[["bd21c004.493b1"]]}]

Okay thank you ! I think yes it's just a timing issue.
Thank you so much for helping me :slight_smile:

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