<aside> đź’ˇ THE STARTING POINT:

S7 input example flow

</aside>


  1. To read S7 Inputs you need to install the S7 plugin in Node-RED

    1. On the right side in Node-RED you need to click on “Manage palette”

      Untitled

    2. Then go to “Install” and search for the “node-red-contrib-s7” plugin. Install it, if not yet done.

      Untitled

  2. Use the S7 Input node to access the S7 data points

    Untitled

  3. Set up PLC, Mode and Variable

    1. In order to be able to select the variables of the desired PLC, the correct settings must be made beforehand. To do this, click on the "pencil symbol" next to PLC

      Untitled

    2. Next set the IP address, port, rack and slot. These variables can be obtained from tia portal. In addition, it can be set how often the data of the PLC should be queried. When the settings have been made, click on "add" and you will automatically return to the S7 settings window.

      Untitled

    3. There you can choose the mode (mostly single variable), and the variable itself. For most variables it is definitly enough to only emit on values changes! Caution: For variables that influence the activity or the state, you need them on a regular interval!

  4. Connect all the S7 nodes you want to use in any way (or just store for later use cases) with a function that:

    1. defines the topic of these raw data in the right way
    2. and also replaces null values with zeros.
    var payload = msg.payload
    
    msg.payload = {
        "timestamp_ms": Date.now(), 
    }
    
    if (payload === null) {
        msg.payload[msg.topic.replace(/\\s+/g, '_')] = 0
    } else {
        msg.payload[msg.topic.replace(/\\s+/g, '_')] = payload // replace() function replaces blankspaces with underscores. This is important for Kafka 
    }
    
    msg.topic='ia/raw/dccaachen/printing/'+msg.topic.replace(/\\s+/g, '_')
    
    return msg;
    
  5. After that you only need a MQTT-OUT node with the right server adress (currently it is vernemq:1883)

Untitled