Skip to content

Commit 6f82f66

Browse files
authored
Merge pull request #218 from brentru/fix-retain-overloads
Fix `error: call of overloaded 'publish(char*&, uint8_t [512], size_t&, int)' is ambiguous`
2 parents abe90ec + d6b8436 commit 6f82f66

File tree

3 files changed

+28
-70
lines changed

3 files changed

+28
-70
lines changed

Adafruit_MQTT.cpp

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -365,25 +365,16 @@ bool Adafruit_MQTT::disconnect() {
365365
return disconnectServer();
366366
}
367367

368-
bool Adafruit_MQTT::publish(const char *topic, const char *data, uint8_t qos) {
369-
return publish(topic, (uint8_t *)(data), strlen(data), false, qos);
370-
}
371-
372-
bool Adafruit_MQTT::publish(const char *topic, const char *data, bool retain,
373-
uint8_t qos) {
374-
return publish(topic, (uint8_t *)(data), strlen(data), retain, qos);
375-
}
376-
377-
bool Adafruit_MQTT::publish(const char *topic, uint8_t *data, uint16_t bLen,
378-
uint8_t qos) {
379-
return publish(topic, data, bLen, false, qos);
368+
bool Adafruit_MQTT::publish(const char *topic, const char *data, uint8_t qos,
369+
bool retain) {
370+
return publish(topic, (uint8_t *)(data), strlen(data), qos, retain);
380371
}
381372

382373
bool Adafruit_MQTT::publish(const char *topic, uint8_t *data, uint16_t bLen,
383-
bool retain, uint8_t qos) {
374+
uint8_t qos, bool retain) {
384375
// Construct and send publish packet.
385-
uint16_t len = publishPacket(buffer, topic, data, bLen, retain, qos,
386-
(uint16_t)sizeof(buffer));
376+
uint16_t len = publishPacket(buffer, topic, data, bLen, qos,
377+
(uint16_t)sizeof(buffer), retain);
387378

388379
if (!sendPacket(buffer, len))
389380
return false;
@@ -763,13 +754,7 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
763754
// http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718040
764755
uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
765756
uint8_t *data, uint16_t bLen, uint8_t qos,
766-
uint16_t maxPacketLen) {
767-
return publishPacket(packet, topic, data, bLen, false, qos, maxPacketLen);
768-
}
769-
770-
uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
771-
uint8_t *data, uint16_t bLen, bool retain,
772-
uint8_t qos, uint16_t maxPacketLen) {
757+
uint16_t maxPacketLen, bool retain) {
773758
uint8_t *p = packet;
774759
uint16_t len = 0;
775760

@@ -925,50 +910,33 @@ Adafruit_MQTT_Publish::Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver,
925910
qos = q;
926911
}
927912

928-
bool Adafruit_MQTT_Publish::publish(int32_t i) { return publish(i, false); }
929-
930913
bool Adafruit_MQTT_Publish::publish(int32_t i, bool retain) {
931914
char payload[12];
932915
ltoa(i, payload, 10);
933-
return mqtt->publish(topic, payload, retain, qos);
916+
return mqtt->publish(topic, payload, qos, retain);
934917
}
935918

936-
bool Adafruit_MQTT_Publish::publish(uint32_t i) { return publish(i, false); }
937-
938919
bool Adafruit_MQTT_Publish::publish(uint32_t i, bool retain) {
939920
char payload[11];
940921
ultoa(i, payload, 10);
941-
return mqtt->publish(topic, payload, retain, qos);
942-
}
943-
944-
bool Adafruit_MQTT_Publish::publish(double f, uint8_t precision) {
945-
return publish(f, false, precision);
922+
return mqtt->publish(topic, payload, qos, retain);
946923
}
947924

948-
bool Adafruit_MQTT_Publish::publish(double f, bool retain, uint8_t precision) {
925+
bool Adafruit_MQTT_Publish::publish(double f, uint8_t precision, bool retain) {
949926
char payload[41]; // Need to technically hold float max, 39 digits and minus
950927
// sign.
951928
dtostrf(f, 0, precision, payload);
952-
return mqtt->publish(topic, payload, retain, qos);
953-
}
954-
955-
bool Adafruit_MQTT_Publish::publish(const char *payload) {
956-
return publish(payload, false);
929+
return mqtt->publish(topic, payload, qos, retain);
957930
}
958931

959932
bool Adafruit_MQTT_Publish::publish(const char *payload, bool retain) {
960-
return mqtt->publish(topic, payload, retain, qos);
933+
return mqtt->publish(topic, payload, qos, retain);
961934
}
962935

963936
// publish buffer of arbitrary length
964-
bool Adafruit_MQTT_Publish::publish(uint8_t *payload, uint16_t bLen) {
965-
return publish(payload, bLen, false);
966-
}
967-
968937
bool Adafruit_MQTT_Publish::publish(uint8_t *payload, uint16_t bLen,
969938
bool retain) {
970-
971-
return mqtt->publish(topic, payload, bLen, retain, qos);
939+
return mqtt->publish(topic, payload, bLen, qos, retain);
972940
}
973941

974942
// Adafruit_MQTT_Subscribe Definition //////////////////////////////////////////
@@ -1011,4 +979,4 @@ void Adafruit_MQTT_Subscribe::removeCallback(void) {
1011979
callback_double = 0;
1012980
callback_io = 0;
1013981
io_mqtt = 0;
1014-
}
982+
}

Adafruit_MQTT.h

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,10 @@ class Adafruit_MQTT {
189189

190190
// Publish a message to a topic using the specified QoS level. Returns true
191191
// if the message was published, false otherwise.
192-
bool publish(const char *topic, const char *payload, uint8_t qos = 0);
193-
bool publish(const char *topic, const char *payload, bool retain,
194-
uint8_t qos = 0);
192+
bool publish(const char *topic, const char *payload, uint8_t qos = 0,
193+
bool retain = false);
195194
bool publish(const char *topic, uint8_t *payload, uint16_t bLen,
196-
uint8_t qos = 0);
197-
bool publish(const char *topic, uint8_t *payload, uint16_t bLen, bool retain,
198-
uint8_t qos = 0);
195+
uint8_t qos = 0, bool retain = false);
199196

200197
// Add a subscription to receive messages for a topic. Returns true if the
201198
// subscription could be added or was already present, false otherwise.
@@ -272,11 +269,8 @@ class Adafruit_MQTT {
272269
uint8_t connectPacket(uint8_t *packet);
273270
uint8_t disconnectPacket(uint8_t *packet);
274271
uint16_t publishPacket(uint8_t *packet, const char *topic, uint8_t *payload,
275-
uint16_t bLen, uint8_t qos, uint16_t maxPacketLen = 0);
276-
uint16_t publishPacket(uint8_t *packet, const char *topic, uint8_t *payload,
277-
uint16_t bLen, bool retain, uint8_t qos,
278-
uint16_t maxPacketLen = 0);
279-
272+
uint16_t bLen, uint8_t qos, uint16_t maxPacketLen = 0,
273+
bool retain = false);
280274
uint8_t subscribePacket(uint8_t *packet, const char *topic, uint8_t qos);
281275
uint8_t unsubscribePacket(uint8_t *packet, const char *topic);
282276
uint8_t pingPacket(uint8_t *packet);
@@ -288,20 +282,16 @@ class Adafruit_MQTT_Publish {
288282
Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, const char *feed,
289283
uint8_t qos = 0);
290284

291-
bool publish(const char *s);
292-
bool publish(const char *s, bool retain);
285+
bool publish(const char *s, bool retain = false);
293286
bool publish(
294287
double f,
295288
uint8_t precision =
296-
2); // Precision controls the minimum number of digits after decimal.
297-
// This might be ignored and a higher precision value sent.
298-
bool publish(double f, bool retain, uint8_t precision = 2);
299-
bool publish(int32_t i);
300-
bool publish(int32_t i, bool retain);
301-
bool publish(uint32_t i);
302-
bool publish(uint32_t i, bool retain);
303-
bool publish(uint8_t *b, uint16_t bLen);
304-
bool publish(uint8_t *b, uint16_t bLen, bool retain);
289+
2, // Precision controls the minimum number of digits after decimal.
290+
// This might be ignored and a higher precision value sent.
291+
bool retain = false);
292+
bool publish(int32_t i, bool retain = false);
293+
bool publish(uint32_t i, bool retain = false);
294+
bool publish(uint8_t *b, uint16_t bLen, bool retain = false);
305295

306296
private:
307297
Adafruit_MQTT *mqtt;
@@ -341,4 +331,4 @@ class Adafruit_MQTT_Subscribe {
341331
Adafruit_MQTT *mqtt;
342332
};
343333

344-
#endif
334+
#endif

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit MQTT Library
2-
version=2.5.1
2+
version=2.5.2
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=MQTT library that supports the FONA, ESP8266, ESP32, Yun, and generic Arduino Client hardware.

0 commit comments

Comments
 (0)