Browse our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteris

MQTT Client library for Arduino based PLC's

In this post is showed the MQTT library recommended for Industrial Shields. This library has been tested and used in several installations without any issue.  So we can assure that is stable and reliable. 

Download and additional information: MQTT Library

To install the library we just have to download the .zip file and go to our Arduino IDE. Go to --> Sketch --> Include library --> Add ZIP library. Then select the downloaded file and click to OK button to install this library into the Arduino IDE.

Now we are ready to use it. 


There are several functions to use in this library. 

First of all we must include the library and set up our network connection properly (Wi-Fi, Ethernet, GSM...).

#include <PubSubClient.h>

Then we must indicate the server IP address, initialize a client for our network and for our MQTT connection

IPAddress server(xxx, xxx, xxx, xxx);
EthernetClient ethClient;
PubSubClient client(ethClient);

Initialize client and callback function (optional).

client.setServer(server, port);

After the initialization of the client we have different functions to check, connect, receive and send information.

Use client.connected to verify if the client is connected and use client.connect() to establish communication.

if (!client.connected()){

To subscribe and publish

client.publish(topic, payload);

Apart of this functions you must place the function client.loop() in the loop function to maintain the communication. 

void loop(){

These are the bases to use this MQTT library. Check the Github to know further information. 

Enjoy the library! 

Do you want more information?

Open Source technology allows you to develop your installations.

Just fill the form and we will contact you as soon as we can.