Giter VIP home page Giter VIP logo

Comments (2)

ma-bg avatar ma-bg commented on August 10, 2024 1

Hi @per1234

I appreciate your detailed explanation & tecnical dive in. I changed my code and things work fine now.

from arduinomqttclient.

per1234 avatar per1234 commented on August 10, 2024

Hi @ma-bg. This feature is only available when the MQTT_CLIENT_STD_FUNCTION_CALLBACK macro is defined.

Unfortunately the comment in the source code regarding this is misleading:

// Make this definition in your application code to use std::functions for onMessage callbacks instead of C-pointers:
// #define MQTT_CLIENT_STD_FUNCTION_CALLBACK

The comment implies that you can simply add the #define directive to the sketch:

MySketch.ino:

#define MQTT_CLIENT_STD_FUNCTION_CALLBACK
#include <ArduinoMqttClient.h>

// ...

But this is not possible. The reason is that this only defines the macro in the "translation unit" of the sketch, but not in the translation unit of MqttClient.cpp, where the macro must also be defined. If the macro is not defined in that translation unit, you get an undefined reference error.

There are two approaches to using the feature:

  • Define the macro globally via a -D flag in the compilation command.
  • Define the macro in the library header file.

Arduino IDE 2.x does not provide an interface for the user to define arbitrary global macros so the former is only possible for Arduino IDE users by modifying the compilation command pattern in the boards platform. So the latter approach will be the best option for Arduino IDE users:

  1. Open the MqttClient.h file of your local installation of the library in any text editor.
  2. Change line 36 from this:
    // #define MQTT_CLIENT_STD_FUNCTION_CALLBACK

    To this:
    #define MQTT_CLIENT_STD_FUNCTION_CALLBACK
  3. Save the file.

If you would like further assistance with the configuration of the library or the usage of this feature, you are welcome to post over on Arduino Forum:

https://forum.arduino.cc/

I'm sure we'll be able to help you out over there.

from arduinomqttclient.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.