Inject dynamic variables in s7 nodes

Hello,

I created a flow that read PLC data with the s7 library.
I would like to read the chamber configuration (ip, port, timeout and reading cycle) from a file and then inject those values in the s7 In node, rather than put them with hard code. I have read on the forum that is kind of possible using control s7 node, but I didn't really understand how to do it.

Here is a flow example (without reading file but just with an injection node) :

The PLC configuration would be set in a json file like this :

msg.payload = {
    "ACS": {
        "ip": "XX.XX.XX.XX",
        "port": 102,
        "reading_cycle": 10000,
        "timeout": 500
    }
}
return msg;

And I would like to inject the values like this :

How could I handle this problem ?

Thank you for your help.

Long story short - not possible with current s7 nodes.
Only option is to use npm package nodes7.
Check this first:

My own examples:

There is an S7 package that supports runtime variable readings but I forget which one. Try some of the other contrib packages.

Hello !

I have taken your tips into considerations, thanks. I have created my own node in order to put dynamic variables in the configuration file, which initiates the connection with the PLC. It is also possible to list all the variables you want to read in the same file. The output of this node will deliver an object with all those information.

For the ones who have the same issue as me, you can install it with npm i nodes7-custom-node.
For more information, check the documentation : https://www.npmjs.com/package/nodes7-custom-node

Thank you !

Hey @MystiiK - it looks like you have created a contrib for node-red.

Great stuff. :clap: :clap:

A few pointers if you dont mind:

The name of the node "nodes7-custom-node" is not really in line with Node-RED naming guidelines. The recommendation for naming node-RED contrib nodes is to publish it as @scopename/node-name. I feel something like @mystiik/node-red-s7-dynamic or similar may be better suited? (just my opinion)

Also, since the readme does not mention node-red, I actually had to look at the source to realise it was an installable contrib node for Node-RED.

It should also be tagged with node-red in the package.

Lastly, I note there is no repository link specified in your package. This is very useful for users to let you know if there is an issue.

Also, did you try the existing packages?

Like this one: node-red-contrib-s7-dynamic - npm

Thank you for your recommendations. So I renamed the package and the node properly, but I needed to create another package for that : npm i node-red-contrib-nodes7-dynamic.
The link : https://www.npmjs.com/package/node-red-contrib-nodes7-dynamic
I've also put the keywords in the package, and I deleted the previous one.

To be honest, I didn't try the other packages for two reasons.
First, because I didn't find a good package for my use case (the one you showed was created just one week ago).
Secondly, as an apprentice, I wanted to take the opportunity to create a whole library by myself, for the exercise. It was very rewarding to do it and it helps to understand better how works NodeRED :slight_smile:

Thank you for your help !

I realise that was just added, but there were others and they do support dynamic (runtime specifiable addressing)

Fair enough.

No worries.

A few other things you may wish to address.

  1. you have not added a link to the source repository (ie. no link to the github/gitlab/whatever repository in your package)
    1. This will mark your package down in the node-red flows catalog scoring
    2. Example of high scoring package: node-red-contrib-telegrambot (node) - Node-RED
    3. Example of a low scoring package: node-red-contrib-example-lower-case-mmm (node) - Node-RED
  2. you should consider adding an examples folder and adding 1 or 2 example flows
    5. These become available to users in the import dialog (ctrl-i)
    6. Not having this will mark your package down in the node-red flows catalog scoring
  3. you should add your node to the flows catalog so that users can install it via "Manage Palette"
1 Like

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