You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

CDPStudio MQTT

CDPStudio MQTT Broker Setup

To set up CDPStudio as an MQTT Broker, the MQTTBroker module must be added to the program.

Then, after opening the module and navigating to the table editor, the "ListenAddress" and "ListenPort" properties must be set. The IP should be set to the IPv4 address of the Ethernet Adapter that is used to connect to the PLC, while the port should be set to 1883. The IPv4 address can be found by opening the windows command window and typing the command "ipconfig".

Here, the IPv4 address is 158.37.139.100 which is what will be used.

Now the MQTTBroker setup is finished.


CDPStudio MQTT Client Setup

To publish and subscribe, we also need a client. The MQTTClient module must be added to the program. Then, in the table editor, the properties "BrokerHost" and "BrokerPort" must be set to the MQTTBroker's properties.

Adding a Publisher/Subscriber

To add a publisher or subscriber, the modules "PublishTopic<datatype>" and "SubscriberTopic<datatype>" must be added to the MQTTClient. These modules are only found when the MQTTClient is selected, and can be found under the submenus "PublishTopic" and "SubscribeTopic":

After adding either, the topic must be set.


CODESYS MQTT Setup

WAGO MQTT Setup

Setting up a WAGO PFC200 PLC requires some configuration.

  1. Open the PLC's web server by entering its IP in a web browser and log in.
  2. Press "Configuration" in the menu bar.
  3. In the left menu, press "Cloud Connectivity".
  4. Press "Connection 1".
  5. Check Enabled.
  6. Set "Cloud Platform" to "MQTT AnyCloud".
  7. Set "Hostname" to the CDPStudio MQTTBroker's IP Address
  8. Set "Port Number" to the chosen port (1883).
  9. Set "Client ID" to a recognizable name such as "Wago".
  10. Set "Data Protocol" to "Native MQTT".
  11. Press "Submit".
  12. Press "Reboot" in the top right corner

The Wago is now configured to send MQTT data to the broker correctly.


CODESYS Creating a Publisher

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

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.


CODESYS Creating a Subscriber


MQTT Topic Overview

TopicDatatypePublisherDescription
statusboolPLS

Should be published at the start of every update so CDP can detect loss of connection. Value should always be 1.

water_ecfloatPLSWater EC measurement.
water_phfloatPLSWater PH measurement.
water_tempfloatPLSWater temperature measurement.
air_tempfloatPLSAir temperature measurement.
air_humidityfloatPLSAir humidity measurement.
air_co2floatPLSAir CO2 measurement.
light_stateboolPLSLight state, 1 when on, 0 when off.
light_timeRemainingfloatPLSTime until light toggles on or off, given in hours.









































  • No labels