To be able to publish using MQTT in Codesys some prerequisite changes and settings needs to be done, this is a step by step guide on how to setup mosquitto to publish over MQTT in Codesys.

First step is to change IPv4 settings on the Ethernet port. This is done by going into (Settings → Network & internet → Ethernet) and under the tab IP assigment press edit then change from automatic to manual and turn on IPv4, and change to the settings show in this image:

The PLC which is currently in use has the IP: 158.38.140.53 and the IP for the Ethernet port is set to the same but +/- 1 to the last digit. And change the Subnet mask to 255.255.255.0. 


To setup mosquitto, this has to be downloaded and installed first, after the installation a few lines of code needs to be added to the configuration file mosqitto.conf:

  • listener 1883
  • allow_anonymous true

To start the broker, run the commands:
 

  • cd "C:/Program files/mosquitto"
  • mosquitto -v -c mosquitto.conf

The broker is now running and, the publisher and subscriber can be found at 24_7 MQTT Publisher and 24_7 CDP-Studio Dashboard/24_7 MQTT Subscriber.




  • No labels