Question: Version 1.6.6 - 1.6.7 compile issue with PuSubClient sketch

Hi,
Can someone explain me this:
If I compile the PubSubClient example: mqtt_publish_in_callback with IDE 1.6.5 there is no problem.

Extract of the sketch:

........
EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);
........
// Callback function
void callback(char* topic, byte* payload, unsigned int length) {
.....

Now using IDE 1.6.6 or 1.6.7 I have as foreseen in the example to add twice the definition of the Callback function, otherwise an error message is generated

exit status 1
'callback' was not declared in this scope

Extract of the working sketch

// Callback function header
void callback(char* topic, byte* payload, unsigned int length);
EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);
......
// Callback function
void callback(char* topic, byte* payload, unsigned int length) {
  // In order to republish this payload, a copy must be made
  // as the orignal payload buffer will be overwritten whilst
  // constructing the PUBLISH packet.
  .........

However, looking at the PubSubClient.h I read

#define MQTT_CALLBACK_SIGNATURE void (callback)(char,uint8_t*,unsigned int)
.....
public:
.....
PubSubClient(IPAddress, uint16_t, MQTT_CALLBACK_SIGNATURE,Client& client);

I don't understand this issue and why it was not present with version 1.6.5?

Thanks in advance
Robert

I have the same problem with 1.6.7, any function gives the 'not declared in this scope' error if you include the pubsubclient library. The same problem with the esp8266wifi library.
Something has changed since 1.6.5 but I don't know what...

darvade:

........

EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);
........
// Callback function
void callback(char* topic, byte* payload, unsigned int length) {
.....

The problem is caused by this bug: Auto prototype generation with function as argument to class instantiation · Issue #50 · arduino/arduino-builder · GitHub The problem is that the new preprocessor, arduino-builder(added in Arduino IDE 1.6.6) fails to properly place the automatically generated function prototype for callback() which the old preprocessor did correctly. The half-assed workaround they did to close that issue doesn't help in this case. So, as you have discovered, you must manually create the function prototype before it's referred to in the client object instantiation. The current version of mqtt_publish_in_callback already does this so you must be working with an old version.

kalamgish:
The same problem with the esp8266wifi library.
Something has changed since 1.6.5 but I don't know what...

That's a different issue preprocessor fails on #include "ESP8266wifi.h" (for external ESP8266 addon) · Issue #68 · arduino/arduino-builder · GitHub which has been fixed but is only available in the hourly build.

Hi!

I'm trying to compile this for my ESP8266, but it doesn't;
"mqtt_basic.ino" in "pubsubclient-master".

I get following error:

mqtt_basic:23: error: no matching function for call to 'PubSubClient::PubSubClient(WiFiClient&, IPAddress&)'

So, a solution is to use Arduino IDE 1.6.5, is it?

Regards

Yeah - 1.6.5r5 is the one you want - unless 1.6.8, just released, actually fixes the building issues (I don't have high expectations, considering their recent record...)

Thanks for quick reply.

Sounds good. I have a try tonight.

It worked!

Thanks!