1
0
mirror of https://github.com/adafruit/Adafruit_MQTT_Library.git synced 2025-07-27 15:01:49 +03:00

Allow passing __FlashStringHelper* in addition to char* everywhere

Arduino supplies the F() macro that allows easily putting strings in
PROGMEM and marking them with a custom type. Essentially,
a __FlashStringHelper* is just the same char*, but cast to a different
type, which allows for example Serial.print() to automatically handle
both PROGMEM and normal strings.

By letting this library accept __FlashStringHelper* as well, you can
use easily use the F() macro and reduce the chance of mixing up normal
and PROGMEM pointers.
This commit is contained in:
Matthijs Kooijman
2015-07-24 11:29:22 +02:00
parent 22b77ecb68
commit 5d101b8a7b
2 changed files with 37 additions and 0 deletions

View File

@ -83,6 +83,20 @@ Adafruit_MQTT::Adafruit_MQTT(const char *server, uint16_t port, const char *cid,
}
}
Adafruit_MQTT::Adafruit_MQTT(const __FlashStringHelper *server, uint16_t port, const __FlashStringHelper *cid,
const __FlashStringHelper *user, const __FlashStringHelper *pass) {
servername = (const char *)server;
portnum = port;
clientid = (const char *)cid;
username = (const char *)user;
password = (const char *)pass;
for (uint8_t i=0; i<MAXSUBSCRIPTIONS; i++) {
subscriptions[i] = 0;
}
}
/*
Adafruit_MQTT::Adafruit_MQTT(char *server, uint16_t port, char *cid, char *user, char *pass) {
strncpy(servername, server, SERVERNAME_SIZE);
@ -372,6 +386,13 @@ Adafruit_MQTT_Publish::Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver,
qos = q;
}
Adafruit_MQTT_Publish::Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver,
const __FlashStringHelper *feed, uint8_t q) {
mqtt = mqttserver;
topic = (const char *)feed;
qos = q;
}
bool Adafruit_MQTT_Publish::publish(int32_t i) {
char payload[18];
itoa(i, payload, 10);
@ -403,3 +424,10 @@ Adafruit_MQTT_Subscribe::Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver,
topic = feed;
qos = q;
}
Adafruit_MQTT_Subscribe::Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver,
const __FlashStringHelper *feed, uint8_t q) {
mqtt = mqttserver;
topic = (const char *)feed;
qos = q;
}