From b61d7e70244642bca2c1021a7b438d0ec385796d Mon Sep 17 00:00:00 2001 From: Todd Treece Date: Mon, 15 Aug 2016 13:05:51 -0400 Subject: [PATCH 1/2] remove flashstring helper constructors & methods --- Adafruit_MQTT.cpp | 27 --------------------------- Adafruit_MQTT.h | 11 ----------- 2 files changed, 38 deletions(-) diff --git a/Adafruit_MQTT.cpp b/Adafruit_MQTT.cpp index 45cb0e2..f08ec05 100644 --- a/Adafruit_MQTT.cpp +++ b/Adafruit_MQTT.cpp @@ -204,13 +204,6 @@ int8_t Adafruit_MQTT::connect(const char *user, const char *pass) return connect(); } -int8_t Adafruit_MQTT::connect(const __FlashStringHelper *user, const __FlashStringHelper *pass) -{ - username = (const char*)user; - password = (const char*)pass; - return connect(); -} - uint16_t Adafruit_MQTT::processPacketsUntil(uint8_t *buffer, uint8_t waitforpackettype, uint16_t timeout) { uint16_t len; while (len = readFullPacket(buffer, MAXBUFFERSIZE, timeout)) { @@ -782,14 +775,6 @@ Adafruit_MQTT_Publish::Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, topic = feed; 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[12]; ltoa(i, payload, 10); @@ -834,18 +819,6 @@ Adafruit_MQTT_Subscribe::Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver, io_feed = 0; } -Adafruit_MQTT_Subscribe::Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver, - const __FlashStringHelper *feed, uint8_t q) { - mqtt = mqttserver; - topic = (const char *)feed; - qos = q; - datalen = 0; - callback_uint32t = 0; - callback_buffer = 0; - callback_io = 0; - io_feed = 0; -} - void Adafruit_MQTT_Subscribe::setCallback(SubscribeCallbackUInt32Type cb) { callback_uint32t = cb; } diff --git a/Adafruit_MQTT.h b/Adafruit_MQTT.h index 101b065..d2b2790 100644 --- a/Adafruit_MQTT.h +++ b/Adafruit_MQTT.h @@ -154,7 +154,6 @@ class Adafruit_MQTT { // error. int8_t connect(); int8_t connect(const char *user, const char *pass); - int8_t connect(const __FlashStringHelper *user, const __FlashStringHelper *pass); // Return a printable string version of the error code returned by // connect(). This returns a __FlashStringHelper*, which points to a @@ -172,19 +171,11 @@ class Adafruit_MQTT { // to be called before connect() because it is sent as part of the // connect control packet. bool will(const char *topic, const char *payload, uint8_t qos = 0, uint8_t retain = 0); - bool will(const __FlashStringHelper *topic, const char *payload, uint8_t qos = 0, uint8_t retain = 0) { - return will((const char *)topic, payload, qos, retain); - } // Publish a message to a topic using the specified QoS level. Returns true // if the message was published, false otherwise. - // The topic must be stored in PROGMEM. It can either be a - // char*, or a __FlashStringHelper* (the result of the F() macro). bool publish(const char *topic, const char *payload, uint8_t qos = 0); bool publish(const char *topic, uint8_t *payload, uint16_t bLen, uint8_t qos = 0); - bool publish(const __FlashStringHelper *topic, const char *payload, uint8_t qos = 0) { - return publish((const char *)topic, payload, qos); - } // Add a subscription to receive messages for a topic. Returns true if the // subscription could be added or was already present, false otherwise. @@ -260,7 +251,6 @@ class Adafruit_MQTT { class Adafruit_MQTT_Publish { public: Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, const char *feed, uint8_t qos = 0); - Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, const __FlashStringHelper *feed, uint8_t qos = 0); bool publish(const char *s); bool publish(double f, uint8_t precision=2); // Precision controls the minimum number of digits after decimal. @@ -279,7 +269,6 @@ private: class Adafruit_MQTT_Subscribe { public: Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver, const char *feedname, uint8_t q=0); - Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver, const __FlashStringHelper *feedname, uint8_t q=0); void setCallback(SubscribeCallbackUInt32Type callb); void setCallback(SubscribeCallbackDoubleType callb); From e0c88d8d2c0e458048219f5bde8fd63e0f3cad15 Mon Sep 17 00:00:00 2001 From: Todd Treece Date: Mon, 15 Aug 2016 13:06:17 -0400 Subject: [PATCH 2/2] remove progmem from examples --- .../adafruitio_errors_esp8266.ino | 16 +++++----------- .../adafruitio_secure_esp8266.ino | 10 ++-------- .../mqtt_2subs_esp8266/mqtt_2subs_esp8266.ino | 14 ++++---------- .../mqtt_arbitrary_data/mqtt_arbitrary_data.ino | 10 ++-------- examples/mqtt_cc3k/mqtt_cc3k.ino | 12 +++--------- examples/mqtt_esp8266/mqtt_esp8266.ino | 14 ++++---------- examples/mqtt_fona/mqtt_fona.ino | 4 ++-- 7 files changed, 22 insertions(+), 58 deletions(-) diff --git a/examples/adafruitio_errors_esp8266/adafruitio_errors_esp8266.ino b/examples/adafruitio_errors_esp8266/adafruitio_errors_esp8266.ino index ce43b78..eb027a2 100644 --- a/examples/adafruitio_errors_esp8266/adafruitio_errors_esp8266.ino +++ b/examples/adafruitio_errors_esp8266/adafruitio_errors_esp8266.ino @@ -39,32 +39,26 @@ WiFiClient client; // or... use WiFiFlientSecure for SSL //WiFiClientSecure client; -// Store the MQTT server, username, and password in flash memory. -// This is required for using the Adafruit MQTT library. -const char MQTT_SERVER[] PROGMEM = AIO_SERVER; -const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME; -const char MQTT_PASSWORD[] PROGMEM = AIO_KEY; - // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. -Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD); +Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); /****************************** Feeds ***************************************/ // Setup a feed called 'photocell' for publishing. // Notice MQTT paths for AIO follow the form: /feeds/ -const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell"; +#define PHOTOCELL_FEED AIO_USERNAME "/feeds/photocell" Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED); // Setup a feed called 'onoff' for subscribing to changes. -const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff"; +#define ONOFF_FEED AIO_USERNAME "/feeds/onoff" Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED); /*************************** Error Reporting *********************************/ -const char ERROR_FEED[] PROGMEM = AIO_USERNAME "/errors"; +#define ERROR_FEED AIO_USERNAME "/errors" Adafruit_MQTT_Subscribe errors = Adafruit_MQTT_Subscribe(&mqtt, ERROR_FEED); -const char THROTTLE_FEED[] PROGMEM = AIO_USERNAME "/throttle"; +#define THROTTLE_FEED AIO_USERNAME "/throttle" Adafruit_MQTT_Subscribe throttle = Adafruit_MQTT_Subscribe(&mqtt, THROTTLE_FEED); /*************************** Sketch Code ************************************/ diff --git a/examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino b/examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino index 1468fd1..da7b744 100644 --- a/examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino +++ b/examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino @@ -37,14 +37,8 @@ // WiFiFlientSecure for SSL/TLS support WiFiClientSecure client; -// Store the MQTT server, username, and password in flash memory. -// This is required for using the Adafruit MQTT library. -const char MQTT_SERVER[] PROGMEM = AIO_SERVER; -const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME; -const char MQTT_PASSWORD[] PROGMEM = AIO_KEY; - // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. -Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD); +Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); // io.adafruit.com SHA1 fingerprint 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 // Setup a feed called 'photocell' for publishing. // Notice MQTT paths for AIO follow the form: /feeds/ -const char TEST_FEED[] PROGMEM = AIO_USERNAME "/feeds/test"; +#define TEST_FEED AIO_USERNAME "/feeds/test" Adafruit_MQTT_Publish test = Adafruit_MQTT_Publish(&mqtt, TEST_FEED); /*************************** Sketch Code ************************************/ diff --git a/examples/mqtt_2subs_esp8266/mqtt_2subs_esp8266.ino b/examples/mqtt_2subs_esp8266/mqtt_2subs_esp8266.ino index c68ae9c..ed957c0 100644 --- a/examples/mqtt_2subs_esp8266/mqtt_2subs_esp8266.ino +++ b/examples/mqtt_2subs_esp8266/mqtt_2subs_esp8266.ino @@ -43,22 +43,16 @@ WiFiClient client; // or... use WiFiFlientSecure for SSL //WiFiClientSecure client; -// Store the MQTT server, username, and password in flash memory. -// This is required for using the Adafruit MQTT library. -const char MQTT_SERVER[] PROGMEM = AIO_SERVER; -const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME; -const char MQTT_PASSWORD[] PROGMEM = AIO_KEY; - // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. -Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD); +Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_USERNAME, AIO_KEY); /****************************** Feeds ***************************************/ // Notice MQTT paths for AIO follow the form: /feeds/ // Setup a feed called 'onoff' for subscribing to changes. -const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff"; +#define ONOFF_FEED AIO_USERNAME "/feeds/onoff" Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED); -const char SLIDER_FEED[] PROGMEM = AIO_USERNAME "/feeds/slider"; +#define SLIDER_FEED AIO_USERNAME "/feeds/slider" Adafruit_MQTT_Subscribe slider = Adafruit_MQTT_Subscribe(&mqtt, SLIDER_FEED); /*************************** Sketch Code ************************************/ @@ -163,4 +157,4 @@ void MQTT_connect() { } } Serial.println("MQTT Connected!"); -} \ No newline at end of file +} diff --git a/examples/mqtt_arbitrary_data/mqtt_arbitrary_data.ino b/examples/mqtt_arbitrary_data/mqtt_arbitrary_data.ino index 3d685e6..0eb8060 100644 --- a/examples/mqtt_arbitrary_data/mqtt_arbitrary_data.ino +++ b/examples/mqtt_arbitrary_data/mqtt_arbitrary_data.ino @@ -40,20 +40,14 @@ WiFiClient client; // or... use WiFiFlientSecure for SSL //WiFiClientSecure client; -// Store the MQTT server, username, and password in flash memory. -// This is required for using the Adafruit MQTT library. -const char MQTT_SERVER[] PROGMEM = ARB_SERVER; -const char MQTT_USERNAME[] PROGMEM = ARB_USERNAME; -const char MQTT_PASSWORD[] PROGMEM = ARB_PW; - // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. -Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, ARB_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD); +Adafruit_MQTT_Client mqtt(&client, ARB_SERVER, ARB_SERVERPORT, ARB_USERNAME, ARB_PW); /****************************** Feeds ***************************************/ // Setup a feed called 'arb_packet' for publishing. // Notice MQTT paths for AIO follow the form: /feeds/ -const char ARB_FEED[] PROGMEM = "/feeds/arb_packet"; +#define ARB_FEED "/feeds/arb_packet" Adafruit_MQTT_Publish ap = Adafruit_MQTT_Publish(&mqtt, ARB_FEED); diff --git a/examples/mqtt_cc3k/mqtt_cc3k.ino b/examples/mqtt_cc3k/mqtt_cc3k.ino index c7db7ee..0cd78d5 100644 --- a/examples/mqtt_cc3k/mqtt_cc3k.ino +++ b/examples/mqtt_cc3k/mqtt_cc3k.ino @@ -45,14 +45,8 @@ // Setup the main CC3000 class, just like a normal CC3000 sketch. Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT); -// Store the MQTT server, username, and password in flash memory. -// This is required for using the Adafruit MQTT library. -const char MQTT_SERVER[] PROGMEM = AIO_SERVER; -const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME; -const char MQTT_PASSWORD[] PROGMEM = AIO_KEY; - // Setup the CC3000 MQTT class by passing in the CC3000 class and MQTT server and login details. -Adafruit_MQTT_CC3000 mqtt(&cc3000, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD); +Adafruit_MQTT_CC3000 mqtt(&cc3000, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); // You don't need to change anything below this line! #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 // Setup a feed called 'photocell' for publishing. // Notice MQTT paths for AIO follow the form: /feeds/ -const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell"; +#define PHOTOCELL_FEED AIO_USERNAME "/feeds/photocell" Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED); // Setup a feed called 'onoff' for subscribing to changes. -const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff"; +#define ONOFF_FEED AIO_USERNAME "/feeds/onoff" Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED); /*************************** Sketch Code ************************************/ diff --git a/examples/mqtt_esp8266/mqtt_esp8266.ino b/examples/mqtt_esp8266/mqtt_esp8266.ino index 9df178d..7f77ec1 100644 --- a/examples/mqtt_esp8266/mqtt_esp8266.ino +++ b/examples/mqtt_esp8266/mqtt_esp8266.ino @@ -38,24 +38,18 @@ WiFiClient client; // or... use WiFiFlientSecure for SSL //WiFiClientSecure client; -// Store the MQTT server, username, and password in flash memory. -// This is required for using the Adafruit MQTT library. -const char MQTT_SERVER[] PROGMEM = AIO_SERVER; -const char MQTT_USERNAME[] PROGMEM = AIO_USERNAME; -const char MQTT_PASSWORD[] PROGMEM = AIO_KEY; - // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. -Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_USERNAME, MQTT_PASSWORD); +Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); /****************************** Feeds ***************************************/ // Setup a feed called 'photocell' for publishing. // Notice MQTT paths for AIO follow the form: /feeds/ -const char PHOTOCELL_FEED[] PROGMEM = AIO_USERNAME "/feeds/photocell"; +#define PHOTOCELL_FEED AIO_USERNAME "/feeds/photocell" Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED); // Setup a feed called 'onoff' for subscribing to changes. -const char ONOFF_FEED[] PROGMEM = AIO_USERNAME "/feeds/onoff"; +#define ONOFF_FEED AIO_USERNAME "/feeds/onoff" Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED); /*************************** Sketch Code ************************************/ @@ -152,4 +146,4 @@ void MQTT_connect() { } } Serial.println("MQTT Connected!"); -} \ No newline at end of file +} diff --git a/examples/mqtt_fona/mqtt_fona.ino b/examples/mqtt_fona/mqtt_fona.ino index 183e10c..2f67391 100644 --- a/examples/mqtt_fona/mqtt_fona.ino +++ b/examples/mqtt_fona/mqtt_fona.ino @@ -67,11 +67,11 @@ boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *u // Setup a feed called 'photocell' for publishing. // Notice MQTT paths for AIO follow the form: /feeds/ -const char PHOTOCELL_FEED[] = AIO_USERNAME "/feeds/photocell"; +#define PHOTOCELL_FEED AIO_USERNAME "/feeds/photocell" Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED); // Setup a feed called 'onoff' for subscribing to changes. -const char ONOFF_FEED[] = AIO_USERNAME "/feeds/onoff"; +#define ONOFF_FEED AIO_USERNAME "/feeds/onoff" Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED); /*************************** Sketch Code ************************************/