Merge pull request #53 from adafruit/progmem_fixes

Remove FlashStringHelper Methods
This commit is contained in:
Limor "Ladyada" Fried 2016-08-15 13:19:05 -04:00 committed by GitHub
commit 5e46585e25
9 changed files with 22 additions and 96 deletions

View File

@ -204,13 +204,6 @@ int8_t Adafruit_MQTT::connect(const char *user, const char *pass)
return connect(); 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 Adafruit_MQTT::processPacketsUntil(uint8_t *buffer, uint8_t waitforpackettype, uint16_t timeout) {
uint16_t len; uint16_t len;
while (len = readFullPacket(buffer, MAXBUFFERSIZE, timeout)) { while (len = readFullPacket(buffer, MAXBUFFERSIZE, timeout)) {
@ -782,14 +775,6 @@ Adafruit_MQTT_Publish::Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver,
topic = feed; topic = feed;
qos = q; 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) { bool Adafruit_MQTT_Publish::publish(int32_t i) {
char payload[12]; char payload[12];
ltoa(i, payload, 10); ltoa(i, payload, 10);
@ -834,18 +819,6 @@ Adafruit_MQTT_Subscribe::Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver,
io_feed = 0; 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) { void Adafruit_MQTT_Subscribe::setCallback(SubscribeCallbackUInt32Type cb) {
callback_uint32t = cb; callback_uint32t = cb;
} }

View File

@ -154,7 +154,6 @@ class Adafruit_MQTT {
// error. // error.
int8_t connect(); int8_t connect();
int8_t connect(const char *user, const char *pass); 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 // Return a printable string version of the error code returned by
// connect(). This returns a __FlashStringHelper*, which points to a // 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 // to be called before connect() because it is sent as part of the
// connect control packet. // connect control packet.
bool will(const char *topic, const char *payload, uint8_t qos = 0, uint8_t retain = 0); 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 // 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.
// 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, 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 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 // Add a subscription to receive messages for a topic. Returns true if the
// subscription could be added or was already present, false otherwise. // subscription could be added or was already present, false otherwise.
@ -260,7 +251,6 @@ class Adafruit_MQTT {
class Adafruit_MQTT_Publish { 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);
Adafruit_MQTT_Publish(Adafruit_MQTT *mqttserver, const __FlashStringHelper *feed, uint8_t qos = 0);
bool publish(const 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.
@ -279,7 +269,6 @@ private:
class Adafruit_MQTT_Subscribe { class Adafruit_MQTT_Subscribe {
public: public:
Adafruit_MQTT_Subscribe(Adafruit_MQTT *mqttserver, const char *feedname, uint8_t q=0); 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(SubscribeCallbackUInt32Type callb);
void setCallback(SubscribeCallbackDoubleType callb); void setCallback(SubscribeCallbackDoubleType callb);

View File

@ -39,32 +39,26 @@ WiFiClient client;
// or... use WiFiFlientSecure for SSL // or... use WiFiFlientSecure for SSL
//WiFiClientSecure client; //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. // 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 ***************************************/ /****************************** Feeds ***************************************/
// Setup a feed called 'photocell' for publishing. // Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname> // Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
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); Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
// Setup a feed called 'onoff' for subscribing to changes. // 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); Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
/*************************** Error Reporting *********************************/ /*************************** 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); 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); Adafruit_MQTT_Subscribe throttle = Adafruit_MQTT_Subscribe(&mqtt, THROTTLE_FEED);
/*************************** Sketch Code ************************************/ /*************************** Sketch Code ************************************/

View File

@ -37,14 +37,8 @@
// WiFiFlientSecure for SSL/TLS support // WiFiFlientSecure for SSL/TLS support
WiFiClientSecure client; 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. // 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 // 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"; 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. // Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname> // Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
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); Adafruit_MQTT_Publish test = Adafruit_MQTT_Publish(&mqtt, TEST_FEED);
/*************************** Sketch Code ************************************/ /*************************** Sketch Code ************************************/

View File

@ -43,22 +43,16 @@ WiFiClient client;
// or... use WiFiFlientSecure for SSL // or... use WiFiFlientSecure for SSL
//WiFiClientSecure client; //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. // 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 ***************************************/ /****************************** Feeds ***************************************/
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname> // Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
// Setup a feed called 'onoff' for subscribing to changes. // 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); 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); Adafruit_MQTT_Subscribe slider = Adafruit_MQTT_Subscribe(&mqtt, SLIDER_FEED);
/*************************** Sketch Code ************************************/ /*************************** Sketch Code ************************************/
@ -163,4 +157,4 @@ void MQTT_connect() {
} }
} }
Serial.println("MQTT Connected!"); Serial.println("MQTT Connected!");
} }

View File

@ -40,20 +40,14 @@ WiFiClient client;
// or... use WiFiFlientSecure for SSL // or... use WiFiFlientSecure for SSL
//WiFiClientSecure client; //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. // 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 ***************************************/ /****************************** Feeds ***************************************/
// Setup a feed called 'arb_packet' for publishing. // Setup a feed called 'arb_packet' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname> // Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char ARB_FEED[] PROGMEM = "/feeds/arb_packet"; #define ARB_FEED "/feeds/arb_packet"
Adafruit_MQTT_Publish ap = Adafruit_MQTT_Publish(&mqtt, ARB_FEED); Adafruit_MQTT_Publish ap = Adafruit_MQTT_Publish(&mqtt, ARB_FEED);

View File

@ -45,14 +45,8 @@
// Setup the main CC3000 class, just like a normal CC3000 sketch. // 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); 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. // 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! // You don't need to change anything below this line!
#define halt(s) { Serial.println(F( s )); while(1); } #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. // Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname> // Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
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); Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
// Setup a feed called 'onoff' for subscribing to changes. // 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); Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
/*************************** Sketch Code ************************************/ /*************************** Sketch Code ************************************/

View File

@ -38,24 +38,18 @@ WiFiClient client;
// or... use WiFiFlientSecure for SSL // or... use WiFiFlientSecure for SSL
//WiFiClientSecure client; //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. // 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 ***************************************/ /****************************** Feeds ***************************************/
// Setup a feed called 'photocell' for publishing. // Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname> // Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
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); Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
// Setup a feed called 'onoff' for subscribing to changes. // 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); Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
/*************************** Sketch Code ************************************/ /*************************** Sketch Code ************************************/
@ -152,4 +146,4 @@ void MQTT_connect() {
} }
} }
Serial.println("MQTT Connected!"); Serial.println("MQTT Connected!");
} }

View File

@ -67,11 +67,11 @@ boolean FONAconnect(const __FlashStringHelper *apn, const __FlashStringHelper *u
// Setup a feed called 'photocell' for publishing. // Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname> // Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
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); Adafruit_MQTT_Publish photocell = Adafruit_MQTT_Publish(&mqtt, PHOTOCELL_FEED);
// Setup a feed called 'onoff' for subscribing to changes. // 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); Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt, ONOFF_FEED);
/*************************** Sketch Code ************************************/ /*************************** Sketch Code ************************************/