From 61f75246f42d40ec4b8481e776a35c9261e2b8e4 Mon Sep 17 00:00:00 2001 From: brentrubell Date: Fri, 17 Aug 2018 18:01:52 -0400 Subject: [PATCH] Library Fixes (#127) * Removing warnings * handle reading zero-length packets * updating travis to exclude archived libraries, addin Arduino WiFi101 lib instead * adding esp lib to travis * restrict builds to current hardware platforms * travis, esp8266: skip esp target for non-esp-based examples * adding test skips for zero, fixing fingerprint error bump library version --- .travis.yml | 6 ++++-- Adafruit_MQTT.cpp | 21 +++++++++++-------- Adafruit_MQTT_Client.cpp | 6 ++++++ .../.zero.test.skip | 1 + .../adafruitio_errors_esp8266/.zero.test.skip | 1 + .../adafruitio_secure_esp8266/.zero.test.skip | 1 + .../adafruitio_secure_esp8266.ino | 5 ++--- .../adafruitio_time_esp8266/.zero.test.skip | 1 + examples/mqtt_2subs_esp8266/.zero.test.skip | 1 + examples/mqtt_esp8266/.zero.test.skip | 1 + .../mqtt_esp8266_callback/.esp8266.test.skip | 1 + .../mqtt_esp8266_callback/.zero.test.skip | 1 + examples/mqtt_ethernet/.zero.test.skip | 1 + examples/mqtt_fona/.zero.test.skip | 1 + examples/mqtt_winc1500/.esp8266.test.skip | 1 + examples/mqtt_yun/.esp8266.test.skip | 1 + examples/mqtt_yun/.zero.test.skip | 1 + library.properties | 2 +- 18 files changed, 38 insertions(+), 15 deletions(-) create mode 100644 examples/adafruitio_anon_time_esp8266/.zero.test.skip create mode 100644 examples/adafruitio_errors_esp8266/.zero.test.skip create mode 100644 examples/adafruitio_secure_esp8266/.zero.test.skip create mode 100644 examples/adafruitio_time_esp8266/.zero.test.skip create mode 100644 examples/mqtt_esp8266_callback/.esp8266.test.skip create mode 100644 examples/mqtt_esp8266_callback/.zero.test.skip create mode 100644 examples/mqtt_ethernet/.zero.test.skip create mode 100644 examples/mqtt_fona/.zero.test.skip create mode 100644 examples/mqtt_winc1500/.esp8266.test.skip create mode 100644 examples/mqtt_yun/.esp8266.test.skip diff --git a/.travis.yml b/.travis.yml index b5ea35f..817b3e5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,9 +3,11 @@ sudo: false before_install: - source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh) install: - - arduino --install-library "Adafruit SleepyDog Library,Adafruit FONA Library,Adafruit CC3000 Library,Adafruit_WINC1500" + - arduino --install-library "Adafruit SleepyDog Library","Adafruit FONA Library" script: - - build_main_platforms + - build_platform esp8266 + - arduino --install-library "WiFi101" + - build_platform zero notifications: email: on_success: change diff --git a/Adafruit_MQTT.cpp b/Adafruit_MQTT.cpp index 40f4610..6855f84 100644 --- a/Adafruit_MQTT.cpp +++ b/Adafruit_MQTT.cpp @@ -189,7 +189,6 @@ int8_t Adafruit_MQTT::connect() { success = true; break; } - //Serial.println("\t**failed, retrying!"); } if (! success) return -2; // failed to sub for some reason } @@ -206,15 +205,20 @@ int8_t Adafruit_MQTT::connect(const char *user, const char *pass) uint16_t Adafruit_MQTT::processPacketsUntil(uint8_t *buffer, uint8_t waitforpackettype, uint16_t timeout) { uint16_t len; - while (len = readFullPacket(buffer, MAXBUFFERSIZE, timeout)) { - //DEBUG_PRINT("Packet read size: "); DEBUG_PRINTLN(len); - // TODO: add subscription reading & call back processing here + while(true) { + len = readFullPacket(buffer, MAXBUFFERSIZE, timeout); - if ((buffer[0] >> 4) == waitforpackettype) { - //DEBUG_PRINTLN(F("Found right packet")); + if(len == 0){ + break; + } + + if ((buffer[0] >> 4) == waitforpackettype) + { return len; - } else { + } + else + { ERROR_PRINTLN(F("Dropped a packet")); } } @@ -407,7 +411,6 @@ bool Adafruit_MQTT::unsubscribe(Adafruit_MQTT_Subscribe *sub) { } void Adafruit_MQTT::processPackets(int16_t timeout) { - uint16_t len; uint32_t elapsed = 0, endtime, starttime = millis(); @@ -482,7 +485,7 @@ Adafruit_MQTT_Subscribe *Adafruit_MQTT::readSubscription(int16_t timeout) { if (i==MAXSUBSCRIPTIONS) return NULL; // matching sub not found ??? uint8_t packet_id_len = 0; - uint16_t packetid; + uint16_t packetid = 0; // Check if it is QoS 1, TODO: we dont support QoS 2 if ((buffer[0] & 0x6) == 0x2) { packet_id_len = 2; diff --git a/Adafruit_MQTT_Client.cpp b/Adafruit_MQTT_Client.cpp index e2ecc82..0a4312e 100644 --- a/Adafruit_MQTT_Client.cpp +++ b/Adafruit_MQTT_Client.cpp @@ -53,6 +53,7 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen, uint16_t len = 0; int16_t t = timeout; + while (client->connected() && (timeout >= 0)) { //DEBUG_PRINT('.'); while (client->available()) { @@ -62,6 +63,11 @@ uint16_t Adafruit_MQTT_Client::readPacket(uint8_t *buffer, uint16_t maxlen, buffer[len] = c; //DEBUG_PRINTLN((uint8_t)c, HEX); len++; + + if (maxlen == 0) { // handle zero-length packets + return 0; + } + if (len == maxlen) { // we read all we want, bail DEBUG_PRINT(F("Read data:\t")); DEBUG_PRINTBUFFER(buffer, len); diff --git a/examples/adafruitio_anon_time_esp8266/.zero.test.skip b/examples/adafruitio_anon_time_esp8266/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/adafruitio_anon_time_esp8266/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/examples/adafruitio_errors_esp8266/.zero.test.skip b/examples/adafruitio_errors_esp8266/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/adafruitio_errors_esp8266/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/examples/adafruitio_secure_esp8266/.zero.test.skip b/examples/adafruitio_secure_esp8266/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/adafruitio_secure_esp8266/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino b/examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino index 15d0e78..17b4cff 100644 --- a/examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino +++ b/examples/adafruitio_secure_esp8266/adafruitio_secure_esp8266.ino @@ -40,9 +40,8 @@ WiFiClientSecure client; // Setup the MQTT client class by passing in the WiFi client and MQTT server and login details. Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY); -// io.adafruit.com SHA1 fingerprint. Current fingerprint can be verified via: -// echo | openssl s_client -connect io.adafruit.com:443 |& openssl x509 -fingerprint -noout -#define AIO_SSL_FINGERPRINT "77 00 54 2D DA E7 D8 03 27 31 23 99 EB 27 DB CB A5 4C 57 18" +// io.adafruit.com SHA1 fingerprint +const char* fingerprint = "AD 4B 64 B3 67 40 B5 FC 0E 51 9B BD 25 E9 7F 88 B6 2A A3 5B"; /****************************** Feeds ***************************************/ diff --git a/examples/adafruitio_time_esp8266/.zero.test.skip b/examples/adafruitio_time_esp8266/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/adafruitio_time_esp8266/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/examples/mqtt_2subs_esp8266/.zero.test.skip b/examples/mqtt_2subs_esp8266/.zero.test.skip index e69de29..8b13789 100644 --- a/examples/mqtt_2subs_esp8266/.zero.test.skip +++ b/examples/mqtt_2subs_esp8266/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/examples/mqtt_esp8266/.zero.test.skip b/examples/mqtt_esp8266/.zero.test.skip index e69de29..8b13789 100644 --- a/examples/mqtt_esp8266/.zero.test.skip +++ b/examples/mqtt_esp8266/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/examples/mqtt_esp8266_callback/.esp8266.test.skip b/examples/mqtt_esp8266_callback/.esp8266.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/mqtt_esp8266_callback/.esp8266.test.skip @@ -0,0 +1 @@ + diff --git a/examples/mqtt_esp8266_callback/.zero.test.skip b/examples/mqtt_esp8266_callback/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/mqtt_esp8266_callback/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/examples/mqtt_ethernet/.zero.test.skip b/examples/mqtt_ethernet/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/mqtt_ethernet/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/examples/mqtt_fona/.zero.test.skip b/examples/mqtt_fona/.zero.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/mqtt_fona/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/examples/mqtt_winc1500/.esp8266.test.skip b/examples/mqtt_winc1500/.esp8266.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/mqtt_winc1500/.esp8266.test.skip @@ -0,0 +1 @@ + diff --git a/examples/mqtt_yun/.esp8266.test.skip b/examples/mqtt_yun/.esp8266.test.skip new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/examples/mqtt_yun/.esp8266.test.skip @@ -0,0 +1 @@ + diff --git a/examples/mqtt_yun/.zero.test.skip b/examples/mqtt_yun/.zero.test.skip index e69de29..8b13789 100644 --- a/examples/mqtt_yun/.zero.test.skip +++ b/examples/mqtt_yun/.zero.test.skip @@ -0,0 +1 @@ + diff --git a/library.properties b/library.properties index 2268792..773231f 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=Adafruit MQTT Library -version=0.20.1 +version=0.20.2 author=Adafruit maintainer=Adafruit sentence=MQTT library that supports the FONA, ESP8266, Yun, and generic Arduino Client hardware.