Pubsubclient: mycustom library and pubsubclient call back

Created on 23 Jan 2016  路  4Comments  路  Source: knolleary/pubsubclient

Hi. I am trying to make my own library for my Esp8266 Arduino using ESP8266 library and PubSubClient library. Problem is pubsubclient call back function, It is giving error. May someone please help me? Here are ino, h, cpp and error log files.
h.txt
ino.txt
Error.txt
cpp.txt

Most helpful comment

@tomkcook the @knolleary "version" can also handle this with the ESP8266, as the OP requested:

mqtt.setCallback(std::bind(&YourClass:_yourCallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));

@vickeyhort, can you close this issue?

All 4 comments

Hi,

whilst I can recreate your error, my C++ knowledge is not good enough I know what the fix is.

The problem is this library expects the callback function signature to be:

void (*callback)(char*,uint8_t*,unsigned int)

but you are providing a callback that is a member of a class:

void EspMQTT::callback(char* topic, byte* payload, unsigned int length)

I don't know how to make those two match up in C++.

@vickeyhort - see the repository tomkcook/pubsubclient for a version that can handle this. You can set a callback from a class member function like this:

mqtt.set_callback([this] (char* topic, byte* payload, unsigned int length) { this->callback(topic, payload, length); }

@tomkcook the @knolleary "version" can also handle this with the ESP8266, as the OP requested:

mqtt.setCallback(std::bind(&YourClass:_yourCallback, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3));

@vickeyhort, can you close this issue?

Here is the solution for the problem. Thank you so much @tomkcook for your help.

Was this page helpful?
0 / 5 - 0 ratings