Skip to content

Commit 5e46585

Browse files
authored
Merge pull request #53 from adafruit/progmem_fixes
Remove FlashStringHelper Methods
2 parents c56e1b9 + e0c88d8 commit 5e46585

File tree

9 files changed

+22
-96
lines changed

9 files changed

+22
-96
lines changed

Adafruit_MQTT.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -204,13 +204,6 @@ int8_t Adafruit_MQTT::connect(const char *user, const char *pass)
204204
return connect();
205205
}
206206

207-
int8_t Adafruit_MQTT::connect(const __FlashStringHelper *user, const __FlashStringHelper *pass)
208-
{
209-
username = (const char*)user;
210-
password = (const char*)pass;
211-
return connect();
212-
}
213-
214207
uint16_t Adafruit_MQTT::processPacketsUntil(uint8_t *buffer, uint8_t waitforpackettype, uint16_t timeout) {
215208
uint16_t len;
216209
while (len = readFullPacket(buffer, MAXBUFFERSIZE, timeout)) {
@@ -782,14 +775,6 @@ Adafruit_MQTT_Publish::Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver,
782775
topic = feed;
783776
qos = q;
784777
}
785-
786-
Adafruit_MQTT_Publish::Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver,
787-
const __FlashStringHelper *feed, uint8_t q) {
788-
mqtt = mqttserver;
789-
topic = (const char *)feed;
790-
qos = q;
791-
}
792-
793778
bool Adafruit_MQTT_Publish::publish(int32_t i) {
794779
char payload[12];
795780
ltoa(i, payload, 10);
@@ -834,18 +819,6 @@ Adafruit_MQTT_Subscribe::Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver,
834819
io_feed = 0;
835820
}
836821

837-
Adafruit_MQTT_Subscribe::Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver,
838-
const __FlashStringHelper *feed, uint8_t q) {
839-
mqtt = mqttserver;
840-
topic = (const char *)feed;
841-
qos = q;
842-
datalen = 0;
843-
callback_uint32t = 0;
844-
callback_buffer = 0;
845-
callback_io = 0;
846-
io_feed = 0;
847-
}
848-
849822
void Adafruit_MQTT_Subscribe::setCallback(SubscribeCallbackUInt32Type cb) {
850823
callback_uint32t = cb;
851824
}

Adafruit_MQTT.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,6 @@ class Adafruit_MQTT {
154154
// error.
155155
int8_t connect();
156156
int8_t connect(const char *user, const char *pass);
157-
int8_t connect(const __FlashStringHelper *user, const __FlashStringHelper *pass);
158157

159158
// Return a printable string version of the error code returned by
160159
// connect(). This returns a __FlashStringHelper*, which points to a
@@ -172,19 +171,11 @@ class Adafruit_MQTT {
172171
// to be called before connect() because it is sent as part of the
173172
// connect control packet.
174173
bool will(const char *topic, const char *payload, uint8_t qos = 0, uint8_t retain = 0);
175-
bool will(const __FlashStringHelper *topic, const char *payload, uint8_t qos = 0, uint8_t retain = 0) {
176-
return will((const char *)topic, payload, qos, retain);
177-
}
178174

179175
// Publish a message to a topic using the specified QoS level. Returns true
180176
// if the message was published, false otherwise.
181-
// The topic must be stored in PROGMEM. It can either be a
182-
// char*, or a __FlashStringHelper* (the result of the F() macro).
183177
bool publish(const char *topic, const char *payload, uint8_t qos = 0);
184178
bool publish(const char *topic, uint8_t *payload, uint16_t bLen, uint8_t qos = 0);
185-
bool publish(const __FlashStringHelper *topic, const char *payload, uint8_t qos = 0) {
186-
return publish((const char *)topic, payload, qos);
187-
}
188179

189180
// Add a subscription to receive messages for a topic. Returns true if the
190181
// subscription could be added or was already present, false otherwise.
@@ -260,7 +251,6 @@ class Adafruit_MQTT {
260251
class Adafruit_MQTT_Publish {
261252
public:
262253
Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, const char *feed, uint8_t qos = 0);
263-
Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, const __FlashStringHelper *feed, uint8_t qos = 0);
264254

265255
bool publish(const char *s);
266256
bool publish(double f, uint8_t precision=2); // Precision controls the minimum number of digits after decimal.
@@ -279,7 +269,6 @@ class Adafruit_MQTT_Publish {
279269
class Adafruit_MQTT_Subscribe {
280270
public:
281271
Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver, const char *feedname, uint8_t q=0);
282-
Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver, const __FlashStringHelper *feedname, uint8_t q=0);
283272

284273
void setCallback(SubscribeCallbackUInt32Type callb);
285274
void setCallback(SubscribeCallbackDoubleType callb);

examples/adafruitio_errors_esp8266/adafruitio_errors_esp8266.ino

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,32 +39,26 @@ WiFiClient client;
3939
// or... use WiFiFlientSecure for SSL
4040
//WiFiClientSecure client;
4141

42-
// Store the MQTT server, username, and password in flash memory.
43-
// This is required for using the Adafruit MQTT library.
44-
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
45-
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
46-
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
47-
4842
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
49-
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
43+
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
5044

5145
/****************************** Feeds ***************************************/
5246

5347
// Setup a feed called 'photocell' for publishing.
5448
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
55-
const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell";
49+
#define PHOTOCELL_FEED AIO_USERNAME "/feeds/photocell"
5650
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
5751

5852
// Setup a feed called 'onoff' for subscribing to changes.
59-
const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff";
53+
#define ONOFF_FEED AIO_USERNAME "/feeds/onoff"
6054
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
6155

6256
/*************************** Error Reporting *********************************/
6357

64-
const char ERROR_FEED[] PROGMEM = AIO_USERNAME "/errors";
58+
#define ERROR_FEED AIO_USERNAME "/errors"
6559
Adafruit_MQTT_Subscribe errors = Adafruit_MQTT_Subscribe(&mqtt, ERROR_FEED);
6660

67-
const char THROTTLE_FEED[] PROGMEM = AIO_USERNAME "/throttle";
61+
#define THROTTLE_FEED AIO_USERNAME "/throttle"
6862
Adafruit_MQTT_Subscribe throttle = Adafruit_MQTT_Subscribe(&mqtt, THROTTLE_FEED);
6963

7064
/*************************** Sketch Code ************************************/

examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,8 @@
3737
// WiFiFlientSecure for SSL/TLS support
3838
WiFiClientSecure client;
3939

40-
// Store the MQTT server, username, and password in flash memory.
41-
// This is required for using the Adafruit MQTT library.
42-
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
43-
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
44-
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
45-
4640
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
47-
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
41+
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
4842

4943
// io.adafruit.com SHA1 fingerprint
5044
const char* fingerprint = "26 96 1C 2A 51 07 FD 15 80 96 93 AE F7 32 CE B9 0D 01 55 C4";
@@ -53,7 +47,7 @@ const char* fingerprint = "26 96 1C 2A 51 07 FD 15 80 96 93 AE F7 32 CE B9 0D 01
5347

5448
// Setup a feed called 'photocell' for publishing.
5549
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
56-
const char TEST_FEED[] PROGMEM = AIO_USERNAME "/feeds/test";
50+
#define TEST_FEED AIO_USERNAME "/feeds/test"
5751
Adafruit_MQTT_Publish test = Adafruit_MQTT_Publish(&mqtt, TEST_FEED);
5852

5953
/*************************** Sketch Code ************************************/

examples/mqtt_2subs_esp8266/mqtt_2subs_esp8266.ino

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,22 +43,16 @@ WiFiClient client;
4343
// or... use WiFiFlientSecure for SSL
4444
//WiFiClientSecure client;
4545

46-
// Store the MQTT server, username, and password in flash memory.
47-
// This is required for using the Adafruit MQTT library.
48-
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
49-
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
50-
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
51-
5246
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
53-
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
47+
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_USERNAME, AIO_KEY);
5448

5549
/****************************** Feeds ***************************************/
5650

5751
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
5852
// Setup a feed called 'onoff' for subscribing to changes.
59-
const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff";
53+
#define ONOFF_FEED AIO_USERNAME "/feeds/onoff"
6054
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
61-
const char SLIDER_FEED[] PROGMEM = AIO_USERNAME "/feeds/slider";
55+
#define SLIDER_FEED AIO_USERNAME "/feeds/slider"
6256
Adafruit_MQTT_Subscribe slider = Adafruit_MQTT_Subscribe(&mqtt, SLIDER_FEED);
6357

6458
/*************************** Sketch Code ************************************/
@@ -163,4 +157,4 @@ void MQTT_connect() {
163157
}
164158
}
165159
Serial.println("MQTT Connected!");
166-
}
160+
}

examples/mqtt_arbitrary_data/mqtt_arbitrary_data.ino

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,20 +40,14 @@ WiFiClient client;
4040
// or... use WiFiFlientSecure for SSL
4141
//WiFiClientSecure client;
4242

43-
// Store the MQTT server, username, and password in flash memory.
44-
// This is required for using the Adafruit MQTT library.
45-
const char MQTT_SERVER[] PROGMEM = ARB_SERVER;
46-
const char MQTT_USERNAME[] PROGMEM = ARB_USERNAME;
47-
const char MQTT_PASSWORD[] PROGMEM = ARB_PW;
48-
4943
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
50-
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, ARB_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
44+
Adafruit_MQTT_Client mqtt(&client, ARB_SERVER, ARB_SERVERPORT, ARB_USERNAME, ARB_PW);
5145

5246
/****************************** Feeds ***************************************/
5347

5448
// Setup a feed called 'arb_packet' for publishing.
5549
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
56-
const char ARB_FEED[] PROGMEM = "/feeds/arb_packet";
50+
#define ARB_FEED "/feeds/arb_packet"
5751
Adafruit_MQTT_Publish ap = Adafruit_MQTT_Publish(&mqtt, ARB_FEED);
5852

5953

examples/mqtt_cc3k/mqtt_cc3k.ino

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,8 @@
4545
// Setup the main CC3000 class, just like a normal CC3000 sketch.
4646
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT);
4747

48-
// Store the MQTT server, username, and password in flash memory.
49-
// This is required for using the Adafruit MQTT library.
50-
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
51-
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
52-
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
53-
5448
// Setup the CC3000 MQTT class by passing in the CC3000 class and MQTT server and login details.
55-
Adafruit_MQTT_CC3000 mqtt(&cc3000, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
49+
Adafruit_MQTT_CC3000 mqtt(&cc3000, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
5650

5751
// You don't need to change anything below this line!
5852
#define halt(s) { Serial.println(F( s )); while(1); }
@@ -65,11 +59,11 @@ boolean CC3000connect(const char* wlan_ssid, const char* wlan_pass, uint8_t wlan
6559

6660
// Setup a feed called 'photocell' for publishing.
6761
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
68-
const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell";
62+
#define PHOTOCELL_FEED AIO_USERNAME "/feeds/photocell"
6963
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
7064

7165
// Setup a feed called 'onoff' for subscribing to changes.
72-
const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff";
66+
#define ONOFF_FEED AIO_USERNAME "/feeds/onoff"
7367
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
7468

7569
/*************************** Sketch Code ************************************/

examples/mqtt_esp8266/mqtt_esp8266.ino

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,24 +38,18 @@ WiFiClient client;
3838
// or... use WiFiFlientSecure for SSL
3939
//WiFiClientSecure client;
4040

41-
// Store the MQTT server, username, and password in flash memory.
42-
// This is required for using the Adafruit MQTT library.
43-
const char MQTT_SERVER[] PROGMEM = AIO_SERVER;
44-
const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME;
45-
const char MQTT_PASSWORD[] PROGMEM = AIO_KEY;
46-
4741
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
48-
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD);
42+
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
4943

5044
/****************************** Feeds ***************************************/
5145

5246
// Setup a feed called 'photocell' for publishing.
5347
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
54-
const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell";
48+
#define PHOTOCELL_FEED AIO_USERNAME "/feeds/photocell"
5549
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
5650

5751
// Setup a feed called 'onoff' for subscribing to changes.
58-
const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff";
52+
#define ONOFF_FEED AIO_USERNAME "/feeds/onoff"
5953
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
6054

6155
/*************************** Sketch Code ************************************/
@@ -152,4 +146,4 @@ void MQTT_connect() {
152146
}
153147
}
154148
Serial.println("MQTT Connected!");
155-
}
149+
}

examples/mqtt_fona/mqtt_fona.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *u
6767

6868
// Setup a feed called 'photocell' for publishing.
6969
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
70-
const char PHOTOCELL_FEED[] = AIO_USERNAME "/feeds/photocell";
70+
#define PHOTOCELL_FEED AIO_USERNAME "/feeds/photocell"
7171
Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
7272

7373
// Setup a feed called 'onoff' for subscribing to changes.
74-
const char ONOFF_FEED[] = AIO_USERNAME "/feeds/onoff";
74+
#define ONOFF_FEED AIO_USERNAME "/feeds/onoff"
7575
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
7676

7777
/*************************** Sketch Code ************************************/

0 commit comments

Comments
 (0)