To use MQTT with CODESYS, the WagoAppCloud library must be imported to the project. This can be done by:

  1. Press "Library Manager" in the current project.
  2. Press "Add Library".
  3. Expand "Application".
  4. Select "WagoAppCloud"
  5. Press OK.

A function block can then be created to simplify the use of the library:

Code Source: https://www.youtube.com/watch?v=UnhG15JFjao&t=822s&ab_channel=JugaadTech

TL:DR; FROM VIDEO

The publisher works by:

  1. Set the message to send as a string.
  2. Populate an array of bytes with the string by using wagosysplainmem.MemCopy() function.
  3. Publish to the set topic by triggering the xTrigger of the FbPublishMQTT_2 object.



This block can simply be added in a program like this:

Whenever the trigger gets a rising edge, it will publish the message to the broker.

  • No labels