monstrenyatko / ArduinoMqtt

MQTT client for Arduino
MIT License
72 stars 12 forks source link

Using with Sloeber #18

Closed rapasal closed 5 years ago

rapasal commented 5 years ago

I'm not sure if this is something to bring up on a Sloeber board, or with this library, but I thought I'd try here first. I have a sketch working in Arduino IDE using this ArduinoMqtt library, and wanted to "port" it into an Eclipse project using the Sloeber plugin. The Eclipse project is basically going to be wrapper for this library that handles some of the project specific lower higher level stuff (hope that makes sense). Anyway, some rejigging was needed to move from a single .ino to a .h and .cpp. During the reshuffle I now get an error during compilation when I call mqtt->subscribe().

I can post the full files somewhere if needed, but maybe the following will point out my issue?

In CustomMqtt.cpp I have:

void CustomMqtt::processMessage (MqttClient::MessageData& md) {
    ...
}

and

int8_t CustomMqtt::subscribe (char *topic, MqttClient::QoS qos) {
    MqttClient::Error::type rc = mqtt->subscribe(
        topic, qos, processMessage
    );
    ...
}

Both the above are declared in CustomMqtt.h also.

When I compile I get the error:

no matching function for call to 'MqttClient::subscribe(char*&, MqttClient::QoS&, <unresolved overloaded function type>)'

To me this looks like the same/similar implementation as in the ArduinoMqtt examples, but is there some nuance I am overlooking? Like I said full code can be made available if needed, its just a bit messy at the moment as not complete.

monstrenyatko commented 5 years ago

@rapasal It is hard to say without access to a full project code and structure. Do you have MqttClient.h file included somewhere at the top of your .cpp file/files? Usually, you do not need to modify the library itself. Just include the MqttClient.h main header file and add the MQTTPacket/*.c files to your build script.

I would recommend using the PlatformIO instead of Sloeber. It does support generation of the project for IDE like Eclipse and many other if required. If you go with PlatformIO build you do not need to worry about library files and their dependencies. Just add lib_deps = ArduinoMqtt to the platformio.ini file in your project and include MqttClient.h in your .cpp file. The ArduinoMqtt library will be automatically downloaded from PlatformIO repository.

rapasal commented 5 years ago

I came back to this project after a while and eventually got it running. In case anyone else ends up in the same situation, by making processMessage a static function it compiled!