MQTT Library

Community guides and tutorials
Post Reply
User avatar
Jasin
Posts: 1
Joined: Wed Jan 30, 2019 8:35 am

MQTT Library

Post by Jasin » Thu Mar 07, 2019 4:26 pm

There is an MQTT library compatible with Controllino MAXI and MEGA (Must provide a network implementation).
It can be installed via Library Manager in Arduino IDE see:
Image

After installing the library it is possible to use MQTTClient class:

Code: Select all

MQTTClient client;

MQTT client has to be initialized ie:

Code: Select all

client.begin("broker.shiftr.io", net);
broker.shiftr.io is a free service which provides a rich publish & subscribe communication infrastructure.
net is initialized EthernetClient connection.

Then it is possible to Register a handler for incoming messages

Code: Select all

client.onMessage(messageReceived);
messageReceived is a function, that will be called whenever a message is received from the topic. The function must have two string parameters topic and message ie:

Code: Select all

void messageReceived(String &topic, String &payload) 
{
  Serial.println("incoming: " + topic + " - " + payload);
}

Method for connecting the client with a username and password specified:

Code: Select all

client.connect("Controllino", "try", "try")

Methods for Publish/Subscribe to broker are:

Code: Select all

client.publish("/controllino.biz", "Hello Controllino");
client.subscribe("/controllino.biz");

When Example sketch is used, the communication can be seen on web pages of Shiftr.io:
Image

And on Controllino terminal:
Image

Post Reply