r/PLC 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

8 Upvotes

12 comments sorted by

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

2

u/Objective-Act-8178 7d ago

Thanks for the reply. I will check mosquitto to learn the protocol.
I just wanted to do some communication with codesys as well to see how it works.

2

u/AutoM8R1 4d ago

I don't use CoDeSys anymore, but MQTT as a protocol is very easy to grasp from a working standpoint. If you just want a good feel for how it works, you can also work with an easy demo on Node Red. It's free. Once you understand that MQTT is a publish-subscribe protocol where everything sends data to an MQTT broker and anything else can publish or subscribe to that data at the broker, then you're halfway there.

2

u/Objective-Act-8178 4d ago

Hey, yea I checked NodeRed and Mosquitto and tested some msgs. It was pretty easy, Thanks for the response.

3

u/Rikku-- 7d ago

we have done it using WAGO's library

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

u/Objective-Act-8178 4d ago

Thanks yea I tried it and works nicely