A PLC controls the machine, but it is not built to keep history. Counters, temperatures, alarms and cycle times are constantly overwritten. To analyze production, track energy or prove quality, that data has to be collected and stored in a database such as SQL Server or PostgreSQL.
Option 1: OPC UA
Recent Siemens PLCs, such as the S7-1500 and the latest S7-1200 models, include a built-in OPC UA server. Once it is enabled in TIA Portal and the variables are exposed, a collection service can read them securely and write them to the database. OPC UA is the most standard option, and it works the same way with other brands.
Option 2: S7 communication
Older PLCs such as the S7-300 and S7-400 do not have OPC UA, but they can be read over Ethernet with the native S7 protocol from a small industrial PC, without changing the PLC program. On the S7-1200 and S7-1500, this method requires allowing PUT/GET access and using data blocks without optimized access.
Option 3: an IoT gateway and MQTT
When several machines and brands are involved, a gateway on the shop floor can read each PLC, normalize the data and publish it with MQTT to a central server. This decouples the shop floor from the IT side and scales easily to many lines.
Storing the data
Whatever the protocol, the database needs a clear structure: one table or time-series store for measurements, another for events and alarms, with timestamps and machine identifiers. Sampling rates should match the need — every second for a process value, on change for a state or an alarm — to avoid filling the database with useless data.
Which option to choose
If your PLCs support OPC UA, use it: it is secure and standard. For older Siemens PLCs, S7 communication is reliable and inexpensive. For mixed installations or several sites, a gateway with MQTT is the most flexible. In every case, start with one machine and the few values that matter most, then extend.
