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.Â
HOW 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);
client.setCallback(callback);
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()){
  client.connect();
}
To subscribe and publish
client.publish(topic, payload);
client.subscribe(topic);
Apart from these functions, you must place the function client.loop() in the loop function to maintain the communication.Â
void loop(){Â Â client.loop();
}
These are the bases to use this MQTT library. Check Github to know further information.Â
Enjoy the library!Â
MQTT Client library for Arduino based PLC's