Skip to content

Commit ebf4ae0

Browse files
authored
Merge pull request #18 from adafruit/feed-last-value
Add Feed last value HTTP method and more accurate Data CSV parsing
2 parents 8b68522 + d08d95c commit ebf4ae0

11 files changed

+338
-41
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
*.swo
22
*.swp
33
.DS_Store
4+
.sync
5+
.syntastic_cpp_config
6+
7+
# platformio (testing)
8+
.pioenvs
9+
.piolibdeps
10+
.travis.yml
11+
platformio.ini
12+

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ This library requires the latest version of the [Arduino IDE](https://www.arduin
1414
* Latest version of the [Adafruit MQTT Library](https://github.com/adafruit/Adafruit_MQTT_Library)
1515
* Latest version of the [Arduino HTTP Client Library](https://github.com/arduino-libraries/ArduinoHttpClient)
1616

17+
### Adafruit Feather HUZZAH32 (ESP32)
18+
19+
* Latest version of the [ESP32 Arduino Core](https://github.com/espressif/arduino-esp32#using-through-arduino-ide)
20+
* Latest version of the [Adafruit MQTT Library](https://github.com/adafruit/Adafruit_MQTT_Library)
21+
* Latest version of the [Arduino HTTP Client Library](https://github.com/arduino-libraries/ArduinoHttpClient)
22+
1723
### Adafruit Feather M0 WiFi with ATWINC1500
1824

1925
* Latest version of the [Arduino SAMD Arduino Core](https://github.com/arduino/ArduinoCore-samd)

examples/adafruitio_01_subscribe/adafruitio_01_subscribe.ino

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,15 @@ void setup() {
3232

3333
Serial.print("Connecting to Adafruit IO");
3434

35-
// connect to io.adafruit.com
35+
// because Adafruit IO doesn't support the MQTT
36+
// retain flag right now, we need to load the
37+
// last value for the "counter" feed manually and
38+
// send it our handleMessage function
39+
if (counter->exists()) {
40+
handleMessage(counter->lastValue());
41+
}
42+
43+
// start MQTT connection to io.adafruit.com
3644
io.connect();
3745

3846
// set up a message handler for the count feed.
@@ -41,8 +49,11 @@ void setup() {
4149
// received from adafruit io.
4250
counter->onMessage(handleMessage);
4351

44-
// wait for a connection
45-
while(io.status() < AIO_CONNECTED) {
52+
// wait for an MQTT connection
53+
// NOTE: when blending the HTTP and MQTT API, always use the mqttStatus
54+
// method to check on MQTT connection status specifically
55+
56+
while(io.mqttStatus() < AIO_CONNECTED) {
4657
Serial.print(".");
4758
delay(500);
4859
}

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit IO Arduino
2-
version=2.7.0
2+
version=2.7.1
33
author=Adafruit
44
maintainer=Adafruit <info@adafruit.com>
55
sentence=Arduino library to access Adafruit IO.

src/AdafruitIO.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,17 @@ AdafruitIO::AdafruitIO(const char *user, const char *key)
2929

3030
void errorCallback(char *err, uint16_t len)
3131
{
32-
AIO_ERR_PRINTLN();
33-
AIO_ERR_PRINT("ERROR: ");
34-
AIO_ERR_PRINTLN(err);
35-
AIO_ERR_PRINTLN();
32+
AIO_ERROR_PRINTLN();
33+
AIO_ERROR_PRINT("ERROR: ");
34+
AIO_ERROR_PRINTLN(err);
35+
AIO_ERROR_PRINTLN();
3636
}
3737

3838
void AdafruitIO::connect()
3939
{
4040

41+
AIO_DEBUG_PRINTLN("AdafruitIO::connect()");
42+
4143
if(_err_sub) {
4244
// setup error sub
4345
_err_sub = new Adafruit_MQTT_Subscribe(_mqtt, _err_topic);
@@ -221,7 +223,11 @@ aio_status_t AdafruitIO::mqttStatus()
221223
// if the connection failed,
222224
// return so we don't hammer IO
223225
if(_status == AIO_CONNECT_FAILED)
226+
{
227+
AIO_ERROR_PRINT("mqttStatus() failed to connect");
228+
AIO_ERROR_PRINTLN(_mqtt->connectErrorString(_status));
224229
return _status;
230+
}
225231

226232
if(_mqtt->connected())
227233
return AIO_CONNECTED;

src/AdafruitIO.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#error "This sketch requires Adafruit MQTT Library v0.17.0 or higher. Please install or upgrade using the Library Manager."
3131
#endif
3232

33+
3334
class AdafruitIO {
3435

3536
friend class AdafruitIO_Feed;

0 commit comments

Comments
 (0)