Activity Forums Tutorials MQTT Library Reply To: MQTT Library

  • jasin

    August 10, 2020 at 11:23 am


    Here it is.

    It was tested as PlatformIO project with this config (.ini)

    ; PlatformIO Project Configuration File
    ;   Build options: build flags, source filter
    ;   Upload options: custom upload port, speed and extra flags
    ;   Library options: dependencies, extra library storages
    ;   Advanced options: extra scripting
    ; Please visit documentation for the other options and examples
    platform = atmelavr
    board = controllino_maxi
    framework = arduino
    lib_deps = controllino, ethernet, SPI, MQTT


    #include <SPI.h>

    #include <Controllino.h> /* Usage of CONTROLLINO library allows you to use CONTROLLINO_xx aliases in your sketch. */

    #include <Ethernet.h>

    #include <MQTT.h> ​/* by Joël Gähwiler. Have to be installed via Library Manager. See */


    ​CONTROLLINO - Demonstration of MQTT protocol usage, Version 01

    ​Based on example code by Joël Gähwiler. See .

    ​You can check on your device after a successful

    ​connection here: .

    ​Compatible with CONTROLLINO MAXI, MAXI Automation and MEGA.


    ​Please, select proper target board in Tools-&gt;Board-&gt;Controllino MAXI/MEGA before Upload to your CONTROLLINO.

    ​(Refer to if you do not see the CONTROLLINOs in the Arduino IDE menu Tools-&gt;Board.)

    ​Created 29 Jan 2019

    ​by Jasin


    ​Check for the latest CONTROLLINO related software stuff.

    ​Visit our forum here:


    byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED};

    byte ip[] = {192, 168, 16, 177}; // &lt;- change to match your network

    EthernetClient net;

    MQTTClient client;

    unsigned long lastMillis = 0;

    void connect() {


    ​while (!client.connect("Controllino", "try", "try")) {






    ​// client.unsubscribe("/hello");


    void messageReceived(String &amp;topic, String &amp;payload) {

    ​Serial.println("incoming: " + topic + " - " + payload);


    void setup() {


    ​Ethernet.begin(mac, ip);

    ​// Note: Local domain names (e.g. "Computer.local" on OSX) are not supported by Arduino.

    ​// You need to set the IP address directly.

    ​client.begin("", net);




    void loop() {


    ​if (!client.connected()) {



    ​// publish a message roughly every second.

    ​if (millis() - lastMillis &gt; 1000) {

    ​lastMillis = millis();

    ​client.publish("/", "Hello Controllino");



    /* 2019-01-29: The sketch was successfully tested with Arduino 1.8.5, Controllino Library 3.0.4 and CONTROLLINO MAXI. */