Inhibit node execution/deployment

Hi All,
I'm a new node-red user.
I'm currently working on a Win10 platform with NodeJS v14.18.1 version and Node-Red v2.1.1 version.
In the current project I'm working on, I'm using contrib-s7 module to communicate with a Siemens PLC.
One contrib-S7 node, the S7-In node, used to read variables from PLC, has only an output terminal and I need to inhibit the execution/deployment of this node until I complete some initialization operations.
Can anyone help me to solve this problem?
Thank you in advance.


What kind of initialisation do you need to do?

You don't get too much control over the order of things happening in Node-RED in terms of startup.

The first Tab in the editor should be executed first but after that, things pretty much happen in the order they were added to the flows.

The other option if you can use JavaScript code, is to make use of settings.js which is run very early in the startup process.

Hi "TotallyInformation",
thaks for quick feedback.
I need to initialize some global vars and also to read some config files.
Only when these operations are completed, I can start to read PLC values...this is why I need to allow PLC read node execution only once the previous init flow has been correctly completed.
Any ideas?

In that case, the settings.js file is where you should do that. It has a section that lets you set global variables before Node-RED has started its flows. However, it does mean writing code to read the files rather than relying on flows.

The problem with trying to read files in Node-RED is that the process is asynchronous so it is highly likely that other parts of your flow will have started before the read completes even if you put the flow in the 1st tab.

Node-RED runs on Node.js so the setttings.js has access to the fs and other core Node.js modules. I think that Node-RED itself also makes use of fs-extra which is an excellent module that enhances some of the core file handling - so you should be able to simply require that in settings.js otherwise just add const fs = require('fs') towards the top of settings.js outside of the module.exports along with any file reading. Then pass along any required data in the functionGlobalContext property.

When reading files, obviously, you want to probably use the "sync" versions of file reads so that the process doesn't just carry on regardless before your reads have finished.

What happens if the node is executed before init is complete?
If it's just incoherent data, can you filter it out using a Switch node after S7-In?

Does the S7 node have to be triggered to do a read?

Thanks "TotallyInformation, for your suggestions, but they are quite far away from my knowledges...I'm not sure I can understand and implement as you said what I need...being a node-red user new

Hi jbudd,
I need to initialize some global vars with values read only once from the plc so I cannot allow to initialize these vars with bad values

Hi Ghayne,
what do you mean? Can you clarify a little bit better?
In my project, at initialization phase, the S7-In node is use to read some plc tags to initialize some global vars.
Then a different S7-In node (configured in the same way as the one used for inti phase) has to be "executed" cyclically every 10s to acquire PLC tags.

How do you "execute" it?

You could use a node-red-contrib-simple-gate to block results from the second node until you have initialised the global vars.

1 Like

Sorry for my bad explanation...I meant that the PLC tags are updated every 10s as detailed in the S7-In configuration page here attached.

Thank you, I'll have a look

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