Application-Note: #NR4V1 : Combine S7 and MQTT
- Application-Note: #NR0V1 : Get Node-RED ready on my router
- Application-Note: #NR1V1 : Hello World
This application describes how to communicate with an S7 and display the value in a Node-RED dashboard. The setpoint of an Value is pushed to MQTT Broker and also the current value of an variable is pushed to an MQTT Broker. Both values are then displayed by the Node-RED dashboard and read from the MQTT Broker.For this application-note we provide an Example Flow for Node-RED which displays widgets and reads values from a S7-1200 plc. Please consider that this application is running on the router and can be accessed via http or https://router-ip:1880/ui. You can access it also from outside through an Web2Go link from your mbCONNECT24 account.
Description 1 – Dashboard
This Dashboard displays widgets to visualize data and control setpoints. The setpoint "Room 1 Temperature" is send to an public MQTT Broker as the topic "RoomTemperature". This topic is then again read from the broker and displayed at the widget "Set Temperature". The value "temperature" is read from the S7-1200 plc and send to the public MQTT Broker as the topic "CurrentTemperature". This topic is then again read from the broker and displayed at the widget "Current Temperature".
This example is very easy since it doesn't need any programmed code in a function node.
The following picture shows the flow and gives an impression on how it is organized.
Description 2 - Node-RED FlowTo communicate with an S7 plc you need to choose an input or/and output node.
Description 3 - S7 input and output
Use input if you want to read values and use output if you want to write values of an S7 plc.
Let's take a look deeper into parameter:
Description 4 - S7 ocnnection setup
IP Address should be your plc.
S7-1200 and S7-1500 CPU access requires access using "Slot 1" and you must disable optimized block access (in TIA portal) for the blocks you are using. In addition, you must "Enable GET/PUT Access" in the 1500 controller in TIA Portal. Doing so opens up the controller for other access by other applications as well, so be aware of the security implications of doing this.
Define your variable in the tab "Variables".
Description 5 - variables setup
Syntax of S7 address.
- MR30 - MD30 as REAL
- DB10,INT6 - DB10.DBW6 as INT
- DB10,I6 -same as above
- DB10,INT6.2 - DB10.DBW6 and DB10.DBW8 in an array with length 2
- PIW30 - PIW30 as INT
- DB10,S20.30 - String at offset 20 with length of 30 (actual array length 32 due to format of String type, length byte will be read/written)
- DB10,S20.30.3 - Array of 3 strings at offset 20, each with length of 30 (actual array length 32 due to format of String type, length byte will be read/written)
- DB10,C22.30 - Character array at offset 22 with length of 30 (best to not use this with strings as length byte is ignored)
To communicate with MQTT you need to choose an input or/and output node.
In this example we are using an public MQTT broker : broker.mqttdashboard.com. We are recommending to use this only for testing and tutorials, not for productive usage.
Description 6 - MQTT server setup
If you selected and setup an server address go ahead with defining your topic name
Description 7 - MQTT topic setupSee below the Flow as a file to Import in your application.