Industrielle styresystemer - Wiki
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.
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.
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.
Setting up a WAGO PFC200 PLC requires some configuration.
The Wago is now configured to send MQTT data to the broker correctly.
To use MQTT with CODESYS, the WagoAppCloud library must be imported to the project. This can be done by:
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.
Topic | Datatype | Publisher | Description |
---|---|---|---|
status | bool | PLS | Should be published at the start of every update so CDP can detect loss of connection. Value should always be 1. |
water_ec | float | PLS | Water EC measurement. |
water_ph | float | PLS | Water PH measurement. |
water_temp | float | PLS | Water temperature measurement. |
air_temp | float | PLS | Air temperature measurement. |
air_humidity | float | PLS | Air humidity measurement. |
air_co2 | float | PLS | Air CO2 measurement. |
light_state | bool | PLS | Light state, 1 when on, 0 when off. |
light_timeRemaining | float | PLS | Time until light toggles on or off, given in hours. |