Go Down

Topic: Question: Version 1.6.6 - 1.6.7 compile issue with PuSubClient sketch (Read 3958 times) previous topic - next topic

darvade


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:
Code: [Select]
........
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

Code: [Select]
// 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

kalamgish

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...

pert

Code: [Select]
........
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: https://github.com/arduino/arduino-builder/issues/50 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.

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 https://github.com/arduino/arduino-builder/issues/68 which has been fixed but is only available in the hourly build.

Hallon

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

DrAzzy

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...)
ATTinyCore for x4/x5/x61/x7/x8/x41/1634/828/x313 megaTinyCore for the megaavr ATtinies - Board Manager:
http://drazzy.com/package_drazzy.com_index.json
ATtiny breakouts, mosfets, awesome prototyping board in my store http://tindie.com/stores/DrAzzy

Hallon

Thanks for quick reply.

Sounds good. I have a try tonight.


Go Up