New Approaches for Siemens PLC in Industrial IoT: Complete Solution for Cloud Data via MQTT

I will write a technical article on the integration of Siemens PLC with MQTT for cloud data transmission, under the alias ‘Su Ge’.

New Approaches for Siemens PLC in Industrial IoT: Complete Solution for Cloud Data via MQTT

Recently, many friends in factory automation have asked me: “Su Ge, with all this talk about the Industrial Internet, can our PLC also send data to the cloud?” This is a great question. Today, let’s discuss how to use the MQTT protocol to enable cloud monitoring of data collected by Siemens PLC.

1

What is MQTT?

Speaking of MQTT, it is like a special delivery system. Traditional communication is like point-to-point delivery, while MQTT establishes a delivery hub where everyone puts their packages (data) for others to pick up. This method is particularly suitable for data collection and distribution in industrial settings.

The three core roles of MQTT:

  • Broker: Equivalent to the delivery hub

  • Publisher: The data sender, which is our PLC

  • Subscriber: The data receiver, which can be a mobile app or cloud platform

2

Hardware Preparation

To implement this system, the following hardware is required:

  • S7-1200/1500 series PLC (must support Ethernet functionality)

  • Ethernet switch

  • Industrial PC or Raspberry Pi (used as MQTT relay)

Wiring key points:

  1. The PLC connects to the switch via Ethernet cable

  2. The industrial PC also connects to the same switch

  3. Ensure all devices are on the same subnet

3

PLC Program Design

First, create a data block (DB) in TIA Portal to store the data to be uploaded:

DATA_BLOCK "Cloud_Data"
{ S7_Opt_Access := 'TRUE' }
VERSION := 0.1
NON_RETAIN
   STRUCT
       Temperature : Real;   // Temperature value
       Pressure : Real;     // Pressure value
       Speed : Int;         // Speed
       RunStatus : Bool;    // Running status
   END_STRUCT;
BEGIN
   Temperature := 0.0;
   Pressure := 0.0;
   Speed := 0;
   RunStatus := false;
END_DATA_BLOCK

4

Communication Program Implementation

Add the data processing program in OB1:

// Main program loop
ORGANIZATION_BLOCK "Main"
BEGIN
    // Simulate data collection
    "Cloud_Data".Temperature := "AI_Temperature";  // AI input point
    "Cloud_Data".Pressure := "AI_Pressure";        // AI input point
    "Cloud_Data".Speed := "Motor_Speed";           // Motor speed
    "Cloud_Data".RunStatus := "System_Running";    // System running status
    // Trigger data upload
    IF "Upload_Trigger" THEN
        #Send_Data();
    END_IF;
END_ORGANIZATION_BLOCK

5

MQTT Client Configuration

On the industrial PC, Node-RED needs to be installed, which is a very useful data flow processing tool. Installation steps:

  1. Install Node.js

  2. Run the command: npm install -g node-red

  3. Start: node-red

Node-RED flow configuration:

  1. Add S7 communication nodes and configure the PLC’s IP address

  2. Add MQTT publish nodes and connect to the MQTT server

  3. Set data conversion format, recommended to use JSON

6

Common Issues and Solutions

  1. PLC cannot connect

  • Check IP address configuration

  • Confirm firewall settings

  • Test network connectivity

  1. Data anomalies

  • Check data type conversion

  • Confirm the reasonableness of the sampling period

  • Verify data range

  1. Communication interruption

  • Implement heartbeat detection mechanism

  • Add reconnection functionality

  • Ensure data caching

7

Practical Application Case

In a renovation project of an injection molding workshop, this solution enabled real-time monitoring of 15 injection molding machines:

  • Process parameters such as temperature and pressure

  • Equipment operational status

  • Production statistics

  • Energy consumption analysis

Results:

  • Equipment utilization rate increased by 12%

  • Quality issue traceability time reduced from hours to minutes

  • Maintenance efficiency significantly improved

8

Safety Considerations

  1. Network Security

  • Deploy in an internal network environment

  • Enable data encryption

  • Set access permissions

  1. Data Security

  • Ensure data backup

  • Set up anomaly alerts

  • Record operation logs

9

Practical Exercise Suggestions

  1. Build a basic environment to achieve single measurement point data upload

  2. Add data points for batch data processing

  3. Develop a simple monitoring interface

  4. Add alert functionality and historical records

Additional Notes: There are plans to develop an open-source industrial data acquisition framework. Interested parties can follow related updates. This solution is also applicable to other Ethernet-capable PLCs, requiring only modifications to the communication driver.

MQTT is a very practical IoT protocol that, when combined with PLCs, allows for easy cloud data transmission. I hope this article helps everyone avoid detours and achieve better practices in Industrial IoT projects.

Previous Reviews

01

[Solution] Data Integration Design and Implementation Plan for Siemens PLC and MES System

02

In-depth Analysis of Siemens PLC Applications in Industrial Furnaces: Temperature Curves and Process Control

Leave a Comment