You've already forked Adafruit_MQTT_Library
mirror of
https://github.com/adafruit/Adafruit_MQTT_Library.git
synced 2025-07-21 18:22:06 +03:00
Use function overloading instead of optional arguments
This commit is contained in:
@ -366,14 +366,24 @@ bool Adafruit_MQTT::disconnect() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool Adafruit_MQTT::publish(const char *topic, const char *data, uint8_t qos) {
|
bool Adafruit_MQTT::publish(const char *topic, const char *data, uint8_t qos) {
|
||||||
return publish(topic, (uint8_t *)(data), strlen(data), qos);
|
return publish(topic, (uint8_t*)(data), strlen(data), false, qos);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Adafruit_MQTT::publish(const char *topic, uint8_t *data, uint16_t bLen,
|
bool Adafruit_MQTT::publish(const char *topic, uint8_t *data, uint16_t bLen,
|
||||||
uint8_t qos) {
|
uint8_t qos) {
|
||||||
|
return publish(topic, data, bLen, 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, uint8_t *data, uint16_t bLen,
|
||||||
|
bool retain, uint8_t qos) {
|
||||||
// Construct and send publish packet.
|
// Construct and send publish packet.
|
||||||
uint16_t len =
|
uint16_t len = publishPacket(buffer, topic, data, bLen, retain, qos, (uint16_t)sizeof(buffer));
|
||||||
publishPacket(buffer, topic, data, bLen, qos, (uint16_t)sizeof(buffer));
|
|
||||||
if (!sendPacket(buffer, len))
|
if (!sendPacket(buffer, len))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -753,6 +763,12 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
|
|||||||
uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
|
uint16_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
|
||||||
uint8_t *data, uint16_t bLen, uint8_t qos,
|
uint8_t *data, uint16_t bLen, uint8_t qos,
|
||||||
uint16_t maxPacketLen) {
|
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) {
|
||||||
uint8_t *p = packet;
|
uint8_t *p = packet;
|
||||||
uint16_t len = 0;
|
uint16_t len = 0;
|
||||||
|
|
||||||
@ -907,33 +923,54 @@ Adafruit_MQTT_Publish::Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver,
|
|||||||
topic = feed;
|
topic = feed;
|
||||||
qos = q;
|
qos = q;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Adafruit_MQTT_Publish::publish(int32_t i) {
|
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];
|
char payload[12];
|
||||||
ltoa(i, payload, 10);
|
ltoa(i, payload, 10);
|
||||||
return mqtt->publish(topic, payload, qos);
|
return mqtt->publish(topic, payload, retain, qos);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Adafruit_MQTT_Publish::publish(uint32_t i) {
|
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];
|
char payload[11];
|
||||||
ultoa(i, payload, 10);
|
ultoa(i, payload, 10);
|
||||||
return mqtt->publish(topic, payload, qos);
|
return mqtt->publish(topic, payload, retain, qos);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Adafruit_MQTT_Publish::publish(double f, uint8_t precision) {
|
bool Adafruit_MQTT_Publish::publish(double f, uint8_t precision) {
|
||||||
char payload[41]; // Need to technically hold float max, 39 digits and minus
|
return publish(f, false, precision);
|
||||||
// sign.
|
}
|
||||||
|
|
||||||
|
bool Adafruit_MQTT_Publish::publish(double f, bool retain, uint8_t precision) {
|
||||||
|
char payload[41]; // Need to technically hold float max, 39 digits and minus
|
||||||
|
// sign.
|
||||||
dtostrf(f, 0, precision, payload);
|
dtostrf(f, 0, precision, payload);
|
||||||
return mqtt->publish(topic, payload, qos);
|
return mqtt->publish(topic, payload, retain, qos);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Adafruit_MQTT_Publish::publish(const char *payload) {
|
bool Adafruit_MQTT_Publish::publish(const char *payload) {
|
||||||
return mqtt->publish(topic, payload, qos);
|
return publish(payload, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Adafruit_MQTT_Publish::publish(const char *payload, bool retain) {
|
||||||
|
return mqtt->publish(topic, payload, retain, qos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// publish buffer of arbitrary length
|
// publish buffer of arbitrary length
|
||||||
bool Adafruit_MQTT_Publish::publish(uint8_t *payload, uint16_t bLen) {
|
bool Adafruit_MQTT_Publish::publish(uint8_t *payload, uint16_t bLen) {
|
||||||
|
return publish(payload, bLen, false);
|
||||||
|
}
|
||||||
|
|
||||||
return mqtt->publish(topic, payload, bLen, qos);
|
bool Adafruit_MQTT_Publish::publish(uint8_t *payload, uint16_t bLen, bool retain) {
|
||||||
|
|
||||||
|
return mqtt->publish(topic, payload, bLen, retain, qos);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adafruit_MQTT_Subscribe Definition //////////////////////////////////////////
|
// Adafruit_MQTT_Subscribe Definition //////////////////////////////////////////
|
||||||
|
@ -192,6 +192,8 @@ public:
|
|||||||
bool publish(const char *topic, const char *payload, uint8_t qos = 0);
|
bool publish(const char *topic, const char *payload, uint8_t qos = 0);
|
||||||
bool publish(const char *topic, uint8_t *payload, uint16_t bLen,
|
bool publish(const char *topic, uint8_t *payload, uint16_t bLen,
|
||||||
uint8_t qos = 0);
|
uint8_t qos = 0);
|
||||||
|
bool publish(const char *topic, const char *payload, bool retain, uint8_t qos = 0);
|
||||||
|
bool publish(const char *topic, uint8_t *payload, uint16_t bLen, bool retain, uint8_t qos = 0);
|
||||||
|
|
||||||
// Add a subscription to receive messages for a topic. Returns true if the
|
// Add a subscription to receive messages for a topic. Returns true if the
|
||||||
// subscription could be added or was already present, false otherwise.
|
// subscription could be added or was already present, false otherwise.
|
||||||
@ -268,8 +270,10 @@ private:
|
|||||||
uint8_t connectPacket(uint8_t *packet);
|
uint8_t connectPacket(uint8_t *packet);
|
||||||
uint8_t disconnectPacket(uint8_t *packet);
|
uint8_t disconnectPacket(uint8_t *packet);
|
||||||
uint16_t publishPacket(uint8_t *packet, const char *topic, uint8_t *payload,
|
uint16_t publishPacket(uint8_t *packet, const char *topic, uint8_t *payload,
|
||||||
uint16_t bLen, uint8_t qos, uint16_t maxPacketLen = 0,
|
uint16_t bLen, uint8_t qos, uint16_t maxPacketLen = 0);
|
||||||
bool retain = false);
|
uint16_t publishPacket(uint8_t *packet, const char *topic, uint8_t *payload,
|
||||||
|
uint16_t bLen, bool retain, uint8_t qos, uint16_t maxPacketLen = 0);
|
||||||
|
|
||||||
uint8_t subscribePacket(uint8_t *packet, const char *topic, uint8_t qos);
|
uint8_t subscribePacket(uint8_t *packet, const char *topic, uint8_t qos);
|
||||||
uint8_t unsubscribePacket(uint8_t *packet, const char *topic);
|
uint8_t unsubscribePacket(uint8_t *packet, const char *topic);
|
||||||
uint8_t pingPacket(uint8_t *packet);
|
uint8_t pingPacket(uint8_t *packet);
|
||||||
@ -282,14 +286,19 @@ public:
|
|||||||
uint8_t qos = 0);
|
uint8_t qos = 0);
|
||||||
|
|
||||||
bool publish(const char *s);
|
bool publish(const char *s);
|
||||||
|
bool publish(const char *s, bool retain);
|
||||||
bool publish(
|
bool publish(
|
||||||
double f,
|
double f,
|
||||||
uint8_t precision =
|
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.
|
// 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 publish(int32_t i, bool retain);
|
||||||
bool publish(uint32_t i);
|
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 publish(uint8_t *b, uint16_t bLen, bool retain);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Adafruit_MQTT *mqtt;
|
Adafruit_MQTT *mqtt;
|
||||||
|
Reference in New Issue
Block a user