Years ago, when renovating an old production line, it was difficult to achieve data collection and remote monitoring solely relying on the PLC itself. Later, by adding communication modules and integrating with cloud platforms, not only was the problem solved, but it also brought considerable benefits to the factory. Today, I will share some practical experiences of combining PLC with IoT technology.
1. PLC Data Collection System
Choosing Communication Protocols
Just like choosing a “way to communicate”:
// Common industrial protocols
Field Level:
- Modbus RTU: Simple and reliable
- Profinet: Good real-time performance
- EtherCAT: High-speed synchronization
Enterprise Level:
- MQTT: Lightweight
- OPC UA: Standardized
- HTTP: Easy to integrate
Data Collection Program
// Data collection function block
FUNCTION_BLOCK "Data_Collect"
VAR_INPUT
Enable : BOOL; // Enable signal
Sample_Time : TIME; // Sampling period
END_VAR
VAR
Timer : TON; // Sampling timer
Data_Buffer : ARRAY[0..99] OF REAL;
Buffer_Index : INT;
END_VAR
BEGIN
// Periodic sampling
Timer(IN := #Enable,
PT := #Sample_Time);
IF Timer.Q THEN
// Collect production data
Data_Buffer[Buffer_Index] := "Production_Speed";
Data_Buffer[Buffer_Index+1] := "Temperature";
Data_Buffer[Buffer_Index+2] := "Pressure";
// Update index
Buffer_Index := Buffer_Index + 3;
IF Buffer_Index >= 98 THEN
Buffer_Index := 0;
END_IF;
END_IF;
END_FUNCTION_BLOCK
2. Cloud Platform Integration Plan
MQTT Communication Settings
// MQTT configuration function block
FUNCTION "MQTT_Config" : VOID
VAR_INPUT
Broker_IP : STRING; // Server address
Port : INT; // Port number
Topic : STRING; // Topic
END_VAR
BEGIN
// Configure MQTT client
"MQTT_Client".Connect := TRUE;
"MQTT_Client".ADDR := #Broker_IP;
"MQTT_Client".PORT := #Port;
// Subscribe to topic
IF "MQTT_Client".Connected THEN
"MQTT_Client".Subscribe := TRUE;
"MQTT_Client".Topic := #Topic;
END_IF;
END_FUNCTION
Data Packaging and Sending
// JSON data encapsulation
FUNCTION "Pack_JSON" : STRING
VAR_INPUT
Device_ID : STRING;
Value : REAL;
TimeStamp : DATE_AND_TIME;
END_VAR
BEGIN
// Assemble JSON string
#Pack_JSON := '{';
#Pack_JSON := CONCAT(#Pack_JSON,
'"device":"');
#Pack_JSON := CONCAT(#Pack_JSON,
#Device_ID);
#Pack_JSON := CONCAT(#Pack_JSON,
'","value":');
#Pack_JSON := CONCAT(#Pack_JSON,
REAL_TO_STRING(#Value));
#Pack_JSON := CONCAT(#Pack_JSON,
'}');
END_FUNCTION
3. Remote Monitoring Implementation
Web Server Configuration
// Web server setup
1. Enable PLC Web server
2. Configure access permissions
3. Set user accounts
4. Open port (default 80)
Data Visualization
<!-- HTML page template -->
<div class="dashboard">
<div class="card">
<h3>Production Speed</h3>
<div class="value" id="speed">0</div>
</div>
<div class="card">
<h3>Device Temperature</h3>
<div class="value" id="temp">0</div>
</div>
</div>
<script>
// Data update script
function updateData() {
fetch('/api/data')
.then(response => response.json())
.then(data => {
document.getElementById('speed')
.innerHTML = data.speed;
document.getElementById('temp')
.innerHTML = data.temp;
});
}
setInterval(updateData, 1000);
</script>
Practical Suggestions
-
1. System Architecture:
-
• Layered design
-
• Modular structure
-
• Standardized interfaces
-
• Data security
-
2. Development Tools:
-
• PLC programming software
-
• Communication debugging tools
-
• Cloud platform SDK
-
• Visualization components
-
3. Key Technologies:
-
• Industrial protocols
-
• Database design
-
• Network security
-
• Real-time monitoring
-
4. Precautions:
-
• Network stability
-
• Data backup
-
• Permission management
-
• Fault recovery
Key capability requirements:
-
1. Basic Knowledge:
-
• PLC programming
-
• Communication protocols
-
• Databases
-
• Web technologies
-
2. Engineering Practice:
-
• System integration
-
• Debugging methods
-
• Operation and maintenance management
-
• Fault diagnosis
-
3. Innovative Applications:
-
• Intelligent algorithms
-
• Predictive maintenance
-
• Energy efficiency optimization
-
• Quality traceability
Implementation step suggestions:
-
1. Preliminary Planning:
-
• Requirement analysis
-
• Solution design
-
• Equipment selection
-
• Budget control
-
2. System Development:
-
• Communication configuration
-
• Data collection
-
• Platform integration
-
• Interface development
-
3. Operation and Maintenance Optimization:
-
• Performance monitoring
-
• Fault analysis
-
• System upgrades
-
• Security hardening
Practice according to the solutions provided in this article, starting with simple data collection, and gradually achieving a complete industrial IoT system. Establish comprehensive project documentation, including system architecture, communication configuration, and interface specifications. Pay attention to network security design, using encrypted transmission and access control. Regularly perform system backups and updates. Reserve system expansion interfaces during development for future functionality upgrades. Establish a sound operation and maintenance system to ensure stable system operation.