Click the blue text to follow!
Rapid Troubleshooting Practices of Structured Text in IoT Applications
1
The Truth Behind the Fault
Last Tuesday, Xiao Zhang rushed over to me, saying: “Master Li, the data acquisition system on production line 3 has malfunctioned again, and the monitoring center can’t see the temperature data. Production is about to stop!” This kid just graduated six months ago and panicked when he encountered this situation. I put down my teacup and smiled, saying: “Let’s go take a look at the problem; I guarantee we can solve it in 20 minutes.”
When we arrived on site, the PLC indicator lights in the control cabinet were normal. I directly took out my laptop and connected to the PLC, glancing at the program. “You see, the problem lies in this segment of ST code,” I pointed at the structured text program on the screen and said to Xiao Zhang.
plc1
Structured Text: The “High-Level Language” in PLCs
Many young engineers only think of ladder diagrams when they hear PLC. However, in modern factories, especially in IoT applications, Structured Text (ST) programming is the best choice for handling complex logic. It is as intuitive to write as we speak.
“Xiao Wang, look at this piece of code; this is why the data isn’t being uploaded:”
IF Sensor_Value < 0 OR Sensor_Value > 1000 THEN
Valid_Data := FALSE;
Error_Code := 2;
ELSE
Valid_Data := TRUE;
ModbusRegisters[100] := Sensor_Value;
END_IF;
“The problem lies in this conditional check. The temperature sensor of this new device has a range change; it can now measure up to 1200 degrees, but the program still uses the old standard, judging it invalid if it exceeds 1000, thus not uploading any data. In such cases, checking the logs is more important than modifying the code; we need to identify the problem before we can address it effectively.”
2
Common “Pits” in IoT Communication
I remember last year when I was working on a project in a chemical plant, a similar issue caused me to work overtime for a week. At that time, we were collecting data from dozens of sensors via PLC and uploading it to the cloud platform, but the data was always intermittent. Later, we found out it wasn’t a network issue, but rather a problem with the data processing logic.
“A little tip for you: when communicating between PLC and IoT devices, first check three things: communication parameters, data format, and timeout settings. It’s like making a phone call; you need to confirm the number is correct, speak the same language, and ensure the waiting time is reasonable.”
I demonstrated the debugging steps to Xiao Zhang:
“First, activate the PLC’s debugging mode to monitor variable values in real-time. You see, this Sensor_Value indeed exceeds 1000, reaching 1120, so Valid_Data has always been FALSE, and the data hasn’t been written to ModbusRegisters at all.”
“Next, check the communication timestamps. You see the time difference between these two exceeds 500ms, indicating an issue with the communication cycle settings; we need to adjust the scan cycle.”
3
Quick Solutions
I modified the code on the spot, changing the temperature upper limit to 1500, and re-downloaded it to the PLC. The monitoring center immediately received the data.
“The modification was simple, but the key is knowing where the problem lies. Over the past twenty years in factories, I have summarized a troubleshooting method: first observe the phenomenon, then check the logs, monitor the variables, and finally make targeted modifications. Many young engineers jump straight to modifying the program, resulting in more chaos.”
I picked up a small blackboard in the workshop and drew a simple flowchart for Xiao Zhang:
Fault Phenomenon → Check System Logs → Monitor Key Variables → Analyze Possible Causes → Targeted Modifications → Verify Solution
“Experienced technicians never act rashly; they always follow this process, which is highly reliable. Speaking of which, when PLCs and IoT are combined, the biggest concern is data conversion issues. Do you know why?”
Xiao Zhang shook his head.
“Because the REAL type data in PLCs and the JSON format required by the cloud platform are completely different. It’s like the soup I make and the one your mom makes might taste different, but they are both essentially soup. Data is the same; when converting formats, it is crucial to ensure precision and unit consistency, otherwise, it could lead to issues like the last fault I resolved, where the temperature value inexplicably multiplied by ten, causing the workshop’s air conditioning to run at maximum all the time.”
4
Summary of Experience
After resolving the fault, I asked Xiao Zhang to help me create a simple document to record this issue, which has been my habit for many years.
“Xiao Zhang, remember, when dealing with systems that combine PLC and IoT, do not blindly trust textbook knowledge. In practical applications, parameter ranges, communication protocols, and data formats are the most prone to issues. When encountering faults, don’t rush; follow the method I taught you step by step, and you will likely resolve it.”
As we left the workshop, I patted Xiao Zhang on the shoulder: “There are no shortcuts in technical work; it’s all about practicing through one fault after another. Next time you encounter a similar problem, come and share your solution approach with me.”