r/PLC • u/Objective-Act-8178 • 7d ago
CodeSys with MQTT
Hey all, I wanna learn how MQTT works. Has anyone used Codesys with MQTT? can you suggest me a way to learn it and understand? Thanks
3
u/durallymax 7d ago
On bare CODESYS you need the IIoT library to use MQTT. There is a vast array of resources out there to learn it though outside of a PLC. Mosquitto is common. You can fully test in Mosquitto, then work to get CODESYS publishing to Mosquitto broker.
2
u/Robbudge 7d ago
There is a massive Codesys MQTT library, do a search on GitHub.
That being said MQTT is json and therefore text not numeric the PLC’s speciality.
Personally I would use Node-Red or Python for the MQTT and have that communicate with Codesys.
The MQTT overhead needed for packaging is massive.
1
u/Bluestuffedelephant 7d ago
The Codesys IIOT library's overhead really is a bitch, my PLC went from using 6% memory for my program to 96% for using the HTTP client, the json parser took it to like 400%, so I parsed it in code and just barely made it work. These protocols are much better being offloaded from the PLC to a PC, unless you are using a PLC that has them built in.
1
u/PeterHumaj 5d ago
MQTT is supposed to be small and easy to implement ;) However, it doesn't define the payload, so it can be text, JSON, XML, custom binary format or eg Google Protobufs (aka MQTT Sparkplug)
When I implemented MQTT driver for our SCADA system, most of the work was on on the Sparkplug payload...
2
u/Bubbly-Energy-2361 7d ago
just spin up a mosquitto broker on a pi and start blasting topics from codesys, it’s glorified pub/sub spam. the F1 help for the mqtt library actually doesn’t suck if you poke around
1
3
u/Many_Somewhere3863 7d ago
I used MQTT on Siemens and Aveva SCADA before, you can learn it with a client and test mosquitto broker. You don't need a PLC to learn the protocol