Applications of Siemens PLC in Industrial IoT

Recently, Industrial Internet of Things (IIoT) has become a hot topic in the field of automation. As an automation engineer with 20 years of experience, today I want to share how to create a simple Industrial IoT application using the S7-1200 PLC. Through this article, you will learn how to collect data with the PLC and upload it to the cloud for remote monitoring and data analysis.

Hardware Preparation

  • • S7-1200 PLC (CPU 1214C DC/DC/DC)
  • • Ethernet Switch
  • • Temperature Sensor (PT100)
  • • Analog Input Module (SM1231 AI)

Basic PLC Network Configuration

Before implementing IoT applications, the network parameters of the PLC must be configured correctly.The most common mistake here is IP address configuration conflicts.

  1. 1. Static IP Configuration
IP Address: 192.168.0.1
Subnet Mask: 255.255.255.0
Default Gateway: 192.168.0.254
  1. 2. DNS Server Settings: You need to enable the “DNS Enable” option in the hardware configuration so that the PLC can access the cloud server via domain name.

Data Acquisition Module

This part mainly deals with the acquisition and conversion of analog values.

// Temperature data acquisition function block
FUNCTION "Temp_Acquisition" : Void
VAR_TEMP
    Raw_Value : Int;    // Raw AD value
    Temp_Value : Real;  // Converted temperature value
END_VAR

BEGIN
    // Read analog input
    #Raw_Value := "AI_Channel_0";
    
    // Convert to actual temperature value (0-27648 corresponds to 0-100℃)
    #Temp_Value := INT_TO_REAL(#Raw_Value) * 100.0 / 27648.0;
    
    // Data filtering (to prevent sudden changes)
    IF ABS(#Temp_Value - "Last_Temp") < 10.0 THEN
        "Current_Temp" := #Temp_Value;
    END_IF;
    
    "Last_Temp" := "Current_Temp";
END_FUNCTION

Would you like me to explain or break down this code?

Communication Protocol Selection

In Industrial IoT applications, the following protocols are mainly used:

  1. 1. MQTT Protocol
  • • Lightweight IoT messaging protocol
  • • Suitable for bandwidth-constrained network environments
  • • Supports publish/subscribe model
  1. 2. TCP/IP Socket Communication
  • • Direct network programming interface
  • • High flexibility but requires custom protocol
  • Note: When using TCP communication, it is essential to handle disconnection reconnections properly

Data Upload to Cloud

Using TIA Portal’s PUT/GET instructions to achieve data transmission:

// Data upload function block
FUNCTION_BLOCK "Data_Upload"
VAR
    TCON_Instance : TCON;
    TSEND_Instance : TSEND;
    Connect : BOOL;
    SendBusy : BOOL;
    ConnectionID : WORD := 1;
    Data_Buffer : ARRAY[0..255] of BYTE;
END_VAR

BEGIN
    // Establish connection
    "TCON_Instance"(
        REQ := NOT #Connect,
        ID := #ConnectionID,
        CONNECT := #TCP_Params,
        DONE => #Connect
    );
    
    // Send data
    IF #Connect THEN
        "TSEND_Instance"(
            REQ := NOT #SendBusy,
            ID := #ConnectionID,
            LEN := 32,
            DATA := #Data_Buffer
        );
    END_IF;
END_FUNCTION_BLOCK

Would you like me to explain or break down this code?

Common Issues and Solutions

  1. 1. Unstable Connection
  • Reason: Network fluctuations or firewall restrictions
  • Solution: Implement an automatic reconnection mechanism and set reasonable timeout periods
  1. 2. Data Loss
  • Reason: Buffer overflow
  • Solution: Implement local data caching and save to DataLog during network disconnection
  1. 3. Security Issues
  • Risk: Unauthorized access and data tampering
  • Protection: Enable SSL encryption and configure access whitelists

Practical Application Cases

In a beverage production line renovation project, we used the S7-1200 to collect the following data:

  • • Production line speed
  • • Product count
  • • Equipment temperature
  • • Energy consumption data

Data is uploaded to the Alibaba Cloud IoT platform every 5 seconds via the MQTT protocol, achieving:

  • • Real-time monitoring of production status
  • • Yield statistical analysis
  • • Equipment warning maintenance
  • • Energy consumption optimization analysis

Precautions

  1. 1. Network security is paramount, and security measures must be taken
  2. 2. Data collection cycles should be set according to actual needs to avoid ineffective communication
  3. 3. Ensure the stability of the PLC program; the communication module should not affect core control functions
  4. 4. Regularly back up configurations and programs

Practical Suggestions

  1. 1. First, test communication functions on the local network
  2. 2. Use Wireshark to capture and analyze communication data
  3. 3. Establish a complete error handling mechanism
  4. 4. Ensure proper data recording and monitoring functions
  5. 5. Reserve system expansion interfaces

Leave a Comment