From 73f5be4e5c6ed2a9b98f81d5cf00d77bb3a2e935 Mon Sep 17 00:00:00 2001 From: Matthijs Kooijman Date: Thu, 2 Jul 2015 12:59:46 +0200 Subject: [PATCH] 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. --- Adafruit_MQTT.cpp | 6 +++--- Adafruit_MQTT.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Adafruit_MQTT.cpp b/Adafruit_MQTT.cpp index 5d98279..d7963dc 100644 --- a/Adafruit_MQTT.cpp +++ b/Adafruit_MQTT.cpp @@ -140,7 +140,7 @@ int8_t Adafruit_MQTT::connect() { 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. uint8_t len = publishPacket(buffer, topic, data, qos); 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, - char *data, uint8_t qos) { + const char *data, uint8_t qos) { uint8_t *p = packet; uint16_t len; @@ -375,7 +375,7 @@ bool Adafruit_MQTT_Publish::publish(uint32_t i) { 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); } diff --git a/Adafruit_MQTT.h b/Adafruit_MQTT.h index c5c76aa..7d89801 100644 --- a/Adafruit_MQTT.h +++ b/Adafruit_MQTT.h @@ -116,7 +116,7 @@ class Adafruit_MQTT { // 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, 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 // subscription could be added, false otherwise. @@ -161,7 +161,7 @@ class Adafruit_MQTT { // Functions to generate MQTT packets. 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 pingPacket(uint8_t *packet); }; @@ -171,7 +171,7 @@ class Adafruit_MQTT_Publish { public: 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. // This might be ignored and a higher precision value sent. bool publish(int32_t i);