How to implement a task scheduler?


To resume, I am working with a S7 PLC and I am aiming to retrieve periodic data and alarms from the S7, so I declared two S7 connectors :

-one for periodic reading
-one for alarm reading


I also add a status node to monitor the state of S7 connectors, javascript function are juste here to add an information to the

msg.payload as msg.payload.nodeid = 'whatever'

Each nodes status, Alarm and Periodic will execute a respective python script ( for Status, for Alarm, for Periodic), but those scripts can't run at the same time.

A scenario example that can't happen :

Periodic sends data and status sends data at same time

So in order to implement a kind of Scheduler, I tried to use the switch node to test the equality of msg.payload.nodeid so that if the msg.payload.nodeid is equal to the alarm id then it must delay the execution of the status script and periodic script (and if the msg.payload.nodeid is equal to periodic id, delay the two others and so on).

The problem is that using the switch node, I am able to distinguish msg.payload.nodeid but can't schedule tasks.

Do you have any idea?

Kind regards

I am a bit lost on the "scheduler" part. What is the use for the switch node ?

Fill in the blanks:
periodic --> ? --> ?

periodic -> scheduler -> exec script

The scheduler part is not clear for me at all, that's why I used the switch node because I thought I can use it to schedule script execution.

An example scenario :

Periodic node sends msg, then if the nodeid is equal to a certain value (00 for the periodic) then we can exec the script in condition not another script is running (alarm or status)

What about the periodic/alarm nodes, what output do these produce ?
(eg periodic -> debug node with full msg)

They produce this type of output (here is the periodic's output)


Then I convert the json object to string and my pass it as an argument to python script.

Here is my complete flow which works but only if periodic, alarm and status don't send at same time.

The periodic and alarm both produce the same output ? There is no information to distinguish the 2 ?

No doesn't send same output.

Alarm output is :



Function node:

t = msg.payload.nodeid

periodic = null //default
alarm = null //default

   periodic = {payload:"do periodic task"}
   alarm = {payload:"do alarm task"}

return [periodic,alarm]

Note that you have to add another output to the function node.
First will be periodic second alarm

*edit this is ofcourse also possible with a switch node.

Ok thanks I'll try to do it with the switch node but I got it.