Invoke every user defined time

Hi

I need to invoke a function every x second, which is provided from string node

the invoke node is only run every pre-defined time (not user control)

so I

  1. reading for dashboard user time on/off and seconds and saving it in
    global.set(“userTimeSec”,msg.payload)
    global.set(“userTimeOnOff”,msg.payload)
  2. invoke every 1 sec
  3. invoke connected it switch and using it with expression condition
  4. some thing like that
    $globalContext(‘userTimeOnOff’) & (( $milis()/1000 % $globalContext(‘userTimeSec’) ) = 0)

this is not working

  1. what is the correct way to write the expression condition
  2. is there better way?

BR

white your function regarding global.set on a function node and just inject every second whatever as input that will run your function every second.

However I don’t see the point why u wanted to write a global variable every second instead of just do it whenever the value has changed, don’t see the sense on doing it.

Regrads

this is not what I ment

  • the user insert time secX in second for running some functionX node
  • from this point the functionX shold run every secX
  • untill user chabge secX

this is done

set time

  • user write time in dashboard text-input
  • this time is saved in global

use time

  • another flow use invoke every second
  • which connected to switch
  • which should use expression condition to check if to call next functioX node
  • the expression condition is not working for me, probably because I do not know the syntex
    $globalContext(‘userTimeOnOff’) & (( $milis()/1000 % $globalContext(‘userTimeSec’) ) = 0)

any suggestion ?
any better way?

thanks

Take a look on the forum, I guess there is valuable information for what u wanted to achieve on this thread.

Regards

thanks
tired to read, still missing some basic to understand

any way tell me if I am wrong
the delay only delay the message for x sec not invoking a message every x sec

so if I want to do it with delay I will need
invoke every 1sec -> delay message userSeconds = 5 -> stack over flow?, message are thrown away?

Regards

yes you will most likely get a stack overflow.

Maybe if you explain what you are doing this for people might be able to give you some other ideas.

If I understand correctly you want to repeat a message at a variable interval. If so then this flow demonstrates one way of doing that.

[{"id":"79629368.aee43c","type":"function","z":"6dc690a3.1abc88","name":"Repeater","func":"// Repeatedly sends the last message passed in\n// pass message with topic \"interval\" to specify repeate time in ms \n\nif (msg.topic === \"interval\") {\n    context.set(\"interval\", msg.payload);\n} else {\n    // and save it in the node context\n    context.set(\"msg\", msg);\n}\n// have we got a message to repeat?\nmsg = context.get(\"msg\");\nif (msg) {\n    // make a local clone of the message to pass on\n    var msgClone = RED.util.cloneMessage(msg);\n    var repeatInterval = context.get(\"interval\");\n    if (repeatInterval === undefined) repeatInterval = 5000;  // default interval ms\n    // pass the message on\n    node.send(msgClone);\n    // loop at given interval re-sending it\n    var tick = context.get('tick') || 0;\n    // clear the repeater and restart\n    if (tick) {\n    \tclearInterval(tick);\n    }\n    tick = setInterval(function() {\n    \tnode.send(msgClone);\n    }, repeatInterval); // re-send at appropriate rate\n    context.set('tick', tick);\n}\nreturn null;","outputs":1,"noerr":0,"x":363,"y":57,"wires":[["255b6bab.07560c"]]},{"id":"2cb59265.11dcee","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"interval","payload":"2000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":129,"y":35,"wires":[["79629368.aee43c"]]},{"id":"4ca75529.d5e9dc","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"","payload":"Message to be repeated","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":152,"y":145,"wires":[["79629368.aee43c"]]},{"id":"d5b5c9dd.d867c","type":"inject","z":"6dc690a3.1abc88","name":"","topic":"interval","payload":"3000","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":73,"wires":[["79629368.aee43c"]]},{"id":"255b6bab.07560c","type":"debug","z":"6dc690a3.1abc88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":554,"y":59,"wires":[]}]

I need to send every user define seconds discovery message to iqrf mesh

The send discovery work with out problem
( node red to mqtt to iqrf demon to transmitor to network)

The issue is how to invoke it every user define seconds

Thanks

Is that not what my flow does?

Probably yes
I will check as soon as possible
Thank you