DMC has found that more of our customers have the need for their PLCs in remote locations to be able to not only report data to a central server but also be capable of accepting commands from the central server.
If this sounds a lot like the Internet of Things, that’s because it is. Only instead of the more common “things” such as light bulbs or thermostats, DMC is connecting large industrial equipment.
The PLC library only requires a few blocks to get up and running with MQTT communication.
While DMC’s embedded and application development service groups have been providing IoT solutions, industrial controllers have been slightly slower to adapt to the latest IoT trends. PLCs are normally only performing local communication and do not implement common IoT communication protocols. DMC has found the MQTT protocol is one of the widely adopted IoT communication protocols, and it is a lightweight protocol making it easier to implement on a PLC.
Fortunately, DMC had already written a MQTT driver for Siemens PLCs and even presented it at the 2017 Siemens Automation Summit. Unfortunately, the driver could only push data from the PLC to a server. There are gateways out there that can be purchased to act as a gateway from a PLC to a remote server, but it would be better to have an integrated library to save on hardware costs and control cabinet space. We had a project that required two-way communication, so I have extended the driver to support communication from the server to the PLC. This driver will serialize any structure in a PLC data block and send it to the server as a raw byte array.
// MQTT communication control driver
#MQTT(sInClientID := 'ClientID',
sInUserName := 'UserName',
sInPassword := '12345',
TCON_Param := "MQTT_TCON_Param",
ERROR_MQTT := #MQTT_Errors);
// Serialize message Structure to be sent
"fcMQTT_SerializeMessageRaw"(sInSerial:='PLC Serial Number or Other Identifier',
sInTopic:='Server MQTT Topic',
sInVersion:='v1', //If you have your server running multiple sets of the same topic
bOutMessageSerialized=>#bTemp); //Turns true when message has entered queue
//Subscribe to message and send to DB
"fcMQTT_DeserializeMessageSubscribe"(sInTopic:='Server MQTT Topic',
iInBufferIndex:=0, //Must be unique for incoming topics
sInSerial:='PLC Serial Number or Other Identifier',
bOutNewMessage=>#bTemp); //Turns true when a new message has been received
Only a few functions and function blocks are needed to get up and running with MQTT communication on a Siemens PLC.
We have used this driver for a few projects already, and it has proven to be robust enough to deploy into the field. The driver has been able to communicate with applications running on both Amazon Web Services and Microsoft Azure.
MQTT can now be used with a Siemens PLC for communication to Amazon Web Services and Microsoft Azure.
The driver is available at https://github.com/jcondonDMC/SiemensMQTT.
- Establishes unencrypted MQTT connection on port 1883 (can be configured for other ports)
- No limit on the number of MQTT publish topics
- Supports QoS 0 & 1
- Supports subscribing to 10 server topics
- Supports QoS 0 & 1
- Can be used on S7-1200 and S7-1500 PLCs
- Optimize memory management of incoming topics
Having this library enables DMC (and other users) to connect their existing Siemens PLCs to the internet of Things without the need for additional hardware.
Learn more about DMC's Manufacturing Automation and Intelligence services.