Open tomkcook opened 8 years ago
I'll refer you to this comment I made over the weekend: https://github.com/knolleary/pubsubclient/issues/115#issuecomment-174217440
As long as this is fully backwards compatible, so any existing sketch will still work, then go ahead.
I'm not sure if all the arduino toolchains have enough C++11 to make this work. I'll experiment and see.
On a quick survey, no other Arduino board supports std::function<>
(or indeed the <functional>
header at all). I'll submit a pull request that makes this change ESP8266-specific, but see what you think.
Hello, since the last update of the library I am having the following error in my library (aREST) when used with the ESP8266:
/Users/marco/Dropbox/Arduino/libraries/aREST/aREST.h:1051: undefined reference to `PubSubClient::setCallback(std::function<void (char, unsigned char, unsigned int)>)'
With Arduino-based sketches, no problems. How to fix this? I think it is linked to this issue. Thanks!
@marcoschwartz hmmm, ok. Will need input from @tomkcook on this as this was his change. We can rollback if it has regressed behaviour. Do you have a pointer to your code? I see the aREST library on github doesn't reference setCallback anywhere so I'm guessing this is a development version?
Thanks for the fast answer! Indeed it's not in the library directly, but I do a client.setCallback(callback);
in all the code using PubSubClient.
I'll have a look.
@marcoschwartz I can't see the problem. Can you double-check what you have on line 573 of PubSubClient.cpp? ie that you have 21b75a2c4aad100a3fc2cb1f04e6a9b147d69a3d in your source tree.
Thanks for the support! Actually I had to revert to 2.4.0 and then update again from the Arduino library manager, and now it works!
Is there some particular reason not to use C++11's
std::function<void(char*, uint8_t*, uint32_t)>
as the callback type instead of a bare function pointer? That would then allow passing pointer to member, lambda, functors etc instead of just ordinary functions.If there's no objection, I'll create a pull request.