1
0
mirror of https://github.com/adafruit/Adafruit_MQTT_Library.git synced 2025-07-21 18:22:06 +03:00

fixes from @ben-willmore on 83af73f4e5

This commit is contained in:
brentru
2022-11-14 16:23:51 -05:00
parent 9409c6373b
commit 28435eaf58
3 changed files with 30 additions and 72 deletions

View File

@ -365,25 +365,16 @@ bool Adafruit_MQTT::disconnect() {
return disconnectServer();
}
bool Adafruit_MQTT::publish(const char *topic, const char *data, uint8_t qos) {
return publish(topic, (uint8_t *)(data), strlen(data), false, qos);
}
bool Adafruit_MQTT::publish(const char *topic, const char *data, bool retain,
uint8_t qos) {
return publish(topic, (uint8_t *)(data), strlen(data), retain, qos);
bool Adafruit_MQTT::publish(const char *topic, const char *data, uint8_t qos,
bool retain) {
return publish(topic, (uint8_t *)(data), strlen(data), qos, retain);
}
bool Adafruit_MQTT::publish(const char *topic, uint8_t *data, uint16_t bLen,
uint8_t qos) {
return publish(topic, data, bLen, false, qos);
}
bool Adafruit_MQTT::publish(const char *topic, uint8_t *data, uint16_t bLen,
bool retain, uint8_t qos) {
uint8_t qos, bool retain) {
// Construct and send publish packet.
uint16_t len = publishPacket(buffer, topic, data, bLen, retain, qos,
(uint16_t)sizeof(buffer));
uint16_t len = publishPacket(buffer, topic, data, bLen, qos,
(uint16_t)sizeof(buffer), retain);
if (!sendPacket(buffer, len))
return false;
@ -763,13 +754,7 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
// http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html#_Toc398718040
uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
uint8_t *data, uint16_t bLen, uint8_t qos,
uint16_t maxPacketLen) {
return publishPacket(packet, topic, data, bLen, false, qos, maxPacketLen);
}
uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
uint8_t *data, uint16_t bLen, bool retain,
uint8_t qos, uint16_t maxPacketLen) {
uint16_t maxPacketLen, bool retain) {
uint8_t *p = packet;
uint16_t len = 0;
@ -925,50 +910,33 @@ Adafruit_MQTT_Publish::Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver,
qos = q;
}
bool Adafruit_MQTT_Publish::publish(int32_t i) { return publish(i, false); }
bool Adafruit_MQTT_Publish::publish(int32_t i, bool retain) {
char payload[12];
ltoa(i, payload, 10);
return mqtt->publish(topic, payload, retain, qos);
return mqtt->publish(topic, payload, qos, retain);
}
bool Adafruit_MQTT_Publish::publish(uint32_t i) { return publish(i, false); }
bool Adafruit_MQTT_Publish::publish(uint32_t i, bool retain) {
char payload[11];
ultoa(i, payload, 10);
return mqtt->publish(topic, payload, retain, qos);
return mqtt->publish(topic, payload, qos, retain);
}
bool Adafruit_MQTT_Publish::publish(double f, uint8_t precision) {
return publish(f, false, precision);
}
bool Adafruit_MQTT_Publish::publish(double f, bool retain, uint8_t precision) {
bool Adafruit_MQTT_Publish::publish(double f, uint8_t precision, bool retain) {
char payload[41]; // Need to technically hold float max, 39 digits and minus
// sign.
dtostrf(f, 0, precision, payload);
return mqtt->publish(topic, payload, retain, qos);
}
bool Adafruit_MQTT_Publish::publish(const char *payload) {
return publish(payload, false);
return mqtt->publish(topic, payload, qos, retain);
}
bool Adafruit_MQTT_Publish::publish(const char *payload, bool retain) {
return mqtt->publish(topic, payload, retain, qos);
return mqtt->publish(topic, payload, qos, retain);
}
// publish buffer of arbitrary length
bool Adafruit_MQTT_Publish::publish(uint8_t *payload, uint16_t bLen) {
return publish(payload, bLen, false);
}
bool Adafruit_MQTT_Publish::publish(uint8_t *payload, uint16_t bLen,
bool retain) {
return mqtt->publish(topic, payload, bLen, retain, qos);
return mqtt->publish(topic, payload, bLen, qos, retain);
}
// Adafruit_MQTT_Subscribe Definition //////////////////////////////////////////
@ -1011,4 +979,4 @@ void Adafruit_MQTT_Subscribe::removeCallback(void) {
callback_double = 0;
callback_io = 0;
io_mqtt = 0;
}
}

View File

@ -34,7 +34,7 @@
#define ADAFRUIT_MQTT_VERSION_PATCH 0
// Uncomment/comment to turn on/off debug output messages.
#define MQTT_DEBUG
// #define MQTT_DEBUG
// Uncomment/comment to turn on/off error output messages.
#define MQTT_ERROR
@ -107,7 +107,7 @@
// Largest full packet we're able to send.
// Need to be able to store at least ~90 chars for a connect packet with full
// 23 char client ID.
#define MAXBUFFERSIZE (512)
#define MAXBUFFERSIZE (150)
#define MQTT_CONN_USERNAMEFLAG 0x80
#define MQTT_CONN_PASSWORDFLAG 0x40
@ -124,7 +124,7 @@
#define SUBSCRIPTIONDATALEN 20
#else
#define MAXSUBSCRIPTIONS 15
#define SUBSCRIPTIONDATALEN MAXBUFFERSIZE
#define SUBSCRIPTIONDATALEN 100
#endif
class AdafruitIO_MQTT; // forward decl
@ -189,13 +189,10 @@ public:
// Publish a message to a topic using the specified QoS level. Returns true
// if the message was published, false otherwise.
bool publish(const char *topic, const char *payload, uint8_t qos = 0);
bool publish(const char *topic, const char *payload, bool retain,
uint8_t qos = 0);
bool publish(const char *topic, const char *payload, uint8_t qos = 0,
bool retain = false);
bool publish(const char *topic, uint8_t *payload, uint16_t bLen,
uint8_t qos = 0);
bool publish(const char *topic, uint8_t *payload, uint16_t bLen, bool retain,
uint8_t qos = 0);
uint8_t qos = 0, bool retain = false);
// Add a subscription to receive messages for a topic. Returns true if the
// subscription could be added or was already present, false otherwise.
@ -272,11 +269,8 @@ private:
uint8_t connectPacket(uint8_t *packet);
uint8_t disconnectPacket(uint8_t *packet);
uint16_t publishPacket(uint8_t *packet, const char *topic, uint8_t *payload,
uint16_t bLen, uint8_t qos, uint16_t maxPacketLen = 0);
uint16_t publishPacket(uint8_t *packet, const char *topic, uint8_t *payload,
uint16_t bLen, bool retain, uint8_t qos,
uint16_t maxPacketLen = 0);
uint16_t bLen, uint8_t qos, uint16_t maxPacketLen = 0,
bool retain = false);
uint8_t subscribePacket(uint8_t *packet, const char *topic, uint8_t qos);
uint8_t unsubscribePacket(uint8_t *packet, const char *topic);
uint8_t pingPacket(uint8_t *packet);
@ -288,20 +282,16 @@ public:
Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, const char *feed,
uint8_t qos = 0);
bool publish(const char *s);
bool publish(const char *s, bool retain);
bool publish(const char *s, bool retain = false);
bool publish(
double f,
uint8_t precision =
2); // Precision controls the minimum number of digits after decimal.
2, // Precision controls the minimum number of digits after decimal.
// This might be ignored and a higher precision value sent.
bool publish(double f, bool retain, uint8_t precision = 2);
bool publish(int32_t i);
bool publish(int32_t i, bool retain);
bool publish(uint32_t i);
bool publish(uint32_t i, bool retain);
bool publish(uint8_t *b, uint16_t bLen);
bool publish(uint8_t *b, uint16_t bLen, bool retain);
bool retain = false);
bool publish(int32_t i, bool retain = false);
bool publish(uint32_t i, bool retain = false);
bool publish(uint8_t *b, uint16_t bLen, bool retain = false);
private:
Adafruit_MQTT *mqtt;
@ -341,4 +331,4 @@ private:
Adafruit_MQTT *mqtt;
};
#endif
#endif

View File

@ -1,5 +1,5 @@
name=Adafruit MQTT Library
version=2.5.1
version=2.5.2
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=MQTT library that supports the FONA, ESP8266, ESP32, Yun, and generic Arduino Client hardware.