Closed ma-bg closed 6 months ago
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:
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:
-D
flag in the compilation command.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:
MqttClient.h
file of your local installation of the library in any text editor.#define MQTT_CLIENT_STD_FUNCTION_CALLBACK
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:
I'm sure we'll be able to help you out over there.
Hi @per1234
I appreciate your detailed explanation & tecnical dive in. I changed my code and things work fine now.
I've added the example from here https://github.com/arduino-libraries/ArduinoMqttClient/pull/35#issue-597871517 to my code.
Then I got the following error:
If I use the plain C function pointer things work fine. Any idea what might trigger my problem?
I'm using Arduino IDE 2.2.1 with an Arduino Nano ESP32.