Use const pointers for payload
The payload data is never modified by the library, so using const is possible without any further changes. Using const allows using a string literal, or String::c_str() as the payload.
This commit is contained in:
parent
d4e27c9b3f
commit
73f5be4e5c
@ -140,7 +140,7 @@ int8_t Adafruit_MQTT::connect() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Adafruit_MQTT::publish(const char *topic, char *data, uint8_t qos) {
|
bool Adafruit_MQTT::publish(const char *topic, const char *data, uint8_t qos) {
|
||||||
// Construct and send publish packet.
|
// Construct and send publish packet.
|
||||||
uint8_t len = publishPacket(buffer, topic, data, qos);
|
uint8_t len = publishPacket(buffer, topic, data, qos);
|
||||||
if (!sendPacket(buffer, len))
|
if (!sendPacket(buffer, len))
|
||||||
@ -294,7 +294,7 @@ uint8_t Adafruit_MQTT::connectPacket(uint8_t *packet) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
|
uint8_t Adafruit_MQTT::publishPacket(uint8_t *packet, const char *topic,
|
||||||
char *data, uint8_t qos) {
|
const char *data, uint8_t qos) {
|
||||||
uint8_t *p = packet;
|
uint8_t *p = packet;
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ bool Adafruit_MQTT_Publish::publish(uint32_t i) {
|
|||||||
return mqtt->publish(topic, payload, qos);
|
return mqtt->publish(topic, payload, qos);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Adafruit_MQTT_Publish::publish(char *payload) {
|
bool Adafruit_MQTT_Publish::publish(const char *payload) {
|
||||||
return mqtt->publish(topic, payload, qos);
|
return mqtt->publish(topic, payload, qos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +116,7 @@ class Adafruit_MQTT {
|
|||||||
|
|
||||||
// Publish a message to a topic using the specified QoS level. Returns true
|
// Publish a message to a topic using the specified QoS level. Returns true
|
||||||
// if the message was published, false otherwise.
|
// if the message was published, false otherwise.
|
||||||
bool publish(const char *topic, char *payload, uint8_t qos);
|
bool publish(const char *topic, const char *payload, uint8_t qos);
|
||||||
|
|
||||||
// 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, false otherwise.
|
// subscription could be added, false otherwise.
|
||||||
@ -161,7 +161,7 @@ class Adafruit_MQTT {
|
|||||||
|
|
||||||
// Functions to generate MQTT packets.
|
// Functions to generate MQTT packets.
|
||||||
uint8_t connectPacket(uint8_t *packet);
|
uint8_t connectPacket(uint8_t *packet);
|
||||||
uint8_t publishPacket(uint8_t *packet, const char *topic, char *payload, uint8_t qos);
|
uint8_t publishPacket(uint8_t *packet, const char *topic, const char *payload, uint8_t qos);
|
||||||
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 pingPacket(uint8_t *packet);
|
uint8_t pingPacket(uint8_t *packet);
|
||||||
};
|
};
|
||||||
@ -171,7 +171,7 @@ class Adafruit_MQTT_Publish {
|
|||||||
public:
|
public:
|
||||||
Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, const char *feed, uint8_t qos = 0);
|
Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, const char *feed, uint8_t qos = 0);
|
||||||
|
|
||||||
bool publish(char *s);
|
bool publish(const char *s);
|
||||||
bool publish(double f, uint8_t precision=2); // Precision controls the minimum number of digits after decimal.
|
bool publish(double f, uint8_t precision=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(int32_t i);
|
bool publish(int32_t i);
|
||||||
|
Loading…
Reference in New Issue
Block a user