Skip to Content

MQTT on M-Duino with OpenPLC and Raspberry PLC

How to configure an M-Duino PLC as MQTT slave with OpenPLC and a Raspberry PLC running Mosquitto as broker — step-by-step setup for industrial MQTT communication
June 18, 2026 by
Boot & Work Corp. S.L, Arnau Tena

En este blog configuraremos un M-Duino como esclavo MQTT y un Raspberry PLC como maestro. Si seguiste nuestro blog anterior en el que usamos Node-RED como maestro, puedes reutilizar los mismos diagramas ladder.

Prerequisite OpenPLC and MQTT Tutorials for M-Duino and Raspberry PLC

This blog is part of a series of blogs about OpenPLC on Arduino and M-Duino. If you still have not familiarized yourself with the software, we recommend you go through the previous blogs first:

First steps with OpenPLC

Modbus on Arduino with OpenPLC

OpenPLC on M-Duino 42+

Mapping any M-Duino on OpenPLC

MQTT on M-Duino with OpenPLC

HTTP on M-Duino with OpenPLC

Hardware Requirements for M-Duino and Raspberry PLC MQTT Integration

Para el maestro usamos un Raspberry PLC con Mosquitto. El cliente es un M-Duino 42+, but you can use any M-Duino or any OpenPLC-compatible board. The client connects to the server through Ethernet, it may be necessary to use an Ethernet switch.

Configuring the Raspberry PLC as MQTT Broker with Node-RED

If you need a reminder on how to connect to your Raspberry PLC, we recommend you take a look at this free course:

First Steps with Raspberry Pi

After connecting to your Raspberry PLC, run these two commands to install Mosquitto:

sudo apt update
sudo apt install mosquitto mosquitto-clients

Now you need to do some edits to the Mosquitto configuration. Execute this command to go to the Mosquitto folder and open the configuration file:

cd /etc/mosquitto
sudo nano mosquitto.conf

Then add these two lines at the end:

listener 1883 0.0.0.0
allow_anonymous true

Save the file, and restart Mosquitto. To restart Mosquitto, use this command:

sudo systemctl restart mosquitto

Now you can create a topic. Slave devices will use this topic to send or receive information to the Raspberry PLC:

mosquitto_sub -h 10.10.11.20 -t "openplc"

We use the 10.10.11.20 ip because we are using the Ethernet port on the top side of the Raspberry PLC. The one at the side would be 10.10.10.20. The topic in this case is "openplc".

After executing that last command, Mosquitto should be listening for any incoming messages.

Configuring M-Duino as MQTT Slave to Publish Messages in OpenPLC

Abre el ejemplo MQTT_Send en OpenPLC (File > Tutorials and Examples).

Crea una nueva variable llamada "msg", asigna el tipo bool y la ubicación %IX0.0. Luego, en el diagrama ladder, cambia el broker de "MQTT_CONNECT0" de 'test.mosquitto.org' a '10.10.11.20', cambia el topic de "MQTT_SEND0" de 'openplc-test-topic' a 'openplc' y cambia el mensaje de 'Hello from OpenPLC!' a la variable "msg". Añade un bloque de función "R_TRIG" justo antes de "SEND" y un "BOOL_TO_STRING" antes de "MESSAGE".

La tabla de variables debe quedar así:


And the ladder diagram like this (ignoring the top part of the blink):


Esto enviará "TRUE" o "FALSE" por MQTT según el valor de %IX0.0, que corresponde a la entrada I0.0 del M-Duino.

To successfully compile and upload the code there are two things you'll need to do:

  • La primera es mapear correctamente tu M-Duino en el OpenPLC Editor. Esto se explica en este blog:

Mapping any M-Duino PLC for OpenPLC

  • La segunda es habilitar Modbus TCP Ethernet. No vamos a usar Modbus TCP, pero al habilitarlo también se activan las funcionalidades necesarias para usar MQTT por Ethernet. Para ello, ve a la pestaña de comunicaciones en el menú "Transfer Program to PLC" y confíguralo. Lo hemos configurado así:

Now you can upload it to the M-Duino. If your Raspberry PLC is still listening for MQTT messages, you should start receiving "FALSE" or "TRUE" messages every second.

Next blog:

Live debugging with OpenPLC

​Search in our Blog

Boot & Work Corp. S.L, Arnau Tena June 18, 2026
Share this post
Tags

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.

PLC Comparison