Skip to content

Commit bf5ff5b

Browse files
author
brentru
committed
Doxygen AdafruitIO_Feed
1 parent 3a15370 commit bf5ff5b

3 files changed

Lines changed: 252 additions & 20 deletions

File tree

src/AdafruitIO.cpp

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,33 @@
11
/*!
22
* @file AdafruitIO.cpp
33
*
4+
* @mainpage Adafruit IO Arduino Client Library
45
*
5-
* Adafruit invests time and resources providing this open source code.
6-
* Please support Adafruit and open source hardware by purchasing
6+
* @section intro_sec Introduction
7+
*
8+
* This is the documentation for the Adafruit IO Arduino library. This library provides
9+
* a simple device independent interface for interacting with Adafruit IO using Arduino.
10+
* It allows you to switch between WiFi (ESP8266, ESP32, AirLift, WINC1500, & WICED),
11+
* Cellular (32u4 FONA), and Ethernet (Ethernet FeatherWing)
12+
*
13+
* Adafruit invests time and resources providing this open source code,
14+
* please support Adafruit and open-source hardware by purchasing
715
* products from Adafruit!
816
*
9-
* Copyright (c) 2015-2016 Adafruit Industries
10-
* Authors: Tony DiCola, Todd Treece
11-
* Licensed under the MIT license.
17+
* @section dependencies Dependencies
18+
*
19+
* This library depends on <a href="https://github.com/arduino-libraries/ArduinoHttpClient">
20+
* ArduinoHTTPClient</a> and <a href="https://github.com/adafruit/Adafruit_MQTT_Library">
21+
* Adafruit MQTT Library</a> being present on your system. Please make sure you have
22+
* installed the latest version before using this library.
23+
*
24+
* @section author Author
25+
*
26+
* Written by Tony DiCola, Todd Treece for Adafruit Industries
27+
*
28+
* @section license License
1229
*
13-
* All text above must be included in any redistribution.
30+
* BSD license, all text here must be included in any redistribution.
1431
*
1532
*/
1633
#include "AdafruitIO.h"

src/AdafruitIO_Feed.cpp

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
#include "AdafruitIO_Feed.h"
1313
#include "AdafruitIO.h"
1414

15+
/**************************************************************************/
16+
/*!
17+
@brief Creates a new instance of an Adafruit IO Feed.
18+
@param *io
19+
Reference to AdafruitIO.
20+
@param *n
21+
Valid feed name.
22+
*/
23+
/**************************************************************************/
1524
AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n)
1625
: AdafruitIO_MQTT() {
1726
_io = io;
@@ -21,6 +30,17 @@ AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n)
2130
_init();
2231
}
2332

33+
/**************************************************************************/
34+
/*!
35+
@brief Creates a new instance of an Adafruit IO Feed.
36+
@param *io
37+
Reference to AdafruitIO.
38+
@param *n
39+
Valid feed name.
40+
@param *un
41+
Feed owner's Adafruit IO username.
42+
*/
43+
/**************************************************************************/
2444
AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n, const char *un)
2545
: AdafruitIO_MQTT() {
2646
_io = io;
@@ -30,6 +50,11 @@ AdafruitIO_Feed::AdafruitIO_Feed(AdafruitIO *io, const char *n, const char *un)
3050
_init();
3151
}
3252

53+
/**************************************************************************/
54+
/*!
55+
@brief Adafruit IO Feed destructor.
56+
*/
57+
/**************************************************************************/
3358
AdafruitIO_Feed::~AdafruitIO_Feed() {
3459
if (_sub)
3560
delete _sub;
@@ -56,61 +81,212 @@ AdafruitIO_Feed::~AdafruitIO_Feed() {
5681
free(_create_url);
5782
}
5883

84+
/**************************************************************************/
85+
/*!
86+
@brief Creates a new onMessage callback.
87+
@param cb
88+
Adafruit IO callback.
89+
*/
90+
/**************************************************************************/
5991
void AdafruitIO_Feed::onMessage(AdafruitIODataCallbackType cb) {
6092
_dataCallback = cb;
6193
}
6294

95+
/**************************************************************************/
96+
/*!
97+
@brief Updates Adafruit IO Feed.
98+
@param value
99+
Value to publish to feed.
100+
@param lat
101+
Latitude metadata.
102+
@param lon
103+
Longitudinal metadata.
104+
@param ele
105+
Elevation metadata.
106+
@return True if data successfully published to feed, False otherwise.
107+
*/
108+
/**************************************************************************/
63109
bool AdafruitIO_Feed::save(char *value, double lat, double lon, double ele) {
64110
data->setValue(value, lat, lon, ele);
65111
return _pub->publish(data->toCSV());
66112
}
67113

114+
/**************************************************************************/
115+
/*!
116+
@brief Updates Adafruit IO Feed.
117+
@param value
118+
Value to publish to feed.
119+
@param lat
120+
Latitude metadata.
121+
@param lon
122+
Longitudinal metadata.
123+
@param ele
124+
Elevation metadata.
125+
@return True if data successfully published to feed, False otherwise.
126+
*/
127+
/**************************************************************************/
68128
bool AdafruitIO_Feed::save(bool value, double lat, double lon, double ele) {
69129
data->setValue(value, lat, lon, ele);
70130
return _pub->publish(data->toCSV());
71131
}
72132

133+
/**************************************************************************/
134+
/*!
135+
@brief Updates Adafruit IO Feed.
136+
@param value
137+
Value to publish to feed.
138+
@param lat
139+
Latitude metadata.
140+
@param lon
141+
Longitudinal metadata.
142+
@param ele
143+
Elevation metadata.
144+
@return True if data successfully published to feed, False otherwise.
145+
*/
146+
/**************************************************************************/
73147
bool AdafruitIO_Feed::save(String value, double lat, double lon, double ele) {
74148
data->setValue(value, lat, lon, ele);
75149
return _pub->publish(data->toCSV());
76150
}
77151

152+
/**************************************************************************/
153+
/*!
154+
@brief Updates Adafruit IO Feed.
155+
@param value
156+
Value to publish to feed.
157+
@param lat
158+
Latitude metadata.
159+
@param lon
160+
Longitudinal metadata.
161+
@param ele
162+
Elevation metadata.
163+
@return True if data successfully published to feed, False otherwise.
164+
*/
165+
/**************************************************************************/
78166
bool AdafruitIO_Feed::save(int value, double lat, double lon, double ele) {
79167
data->setValue(value, lat, lon, ele);
80168
return _pub->publish(data->toCSV());
81169
}
82170

171+
/**************************************************************************/
172+
/*!
173+
@brief Updates Adafruit IO Feed.
174+
@param value
175+
Value to publish to feed.
176+
@param lat
177+
Latitude metadata.
178+
@param lon
179+
Longitudinal metadata.
180+
@param ele
181+
Elevation metadata.
182+
@return True if data successfully published to feed, False otherwise.
183+
*/
184+
/**************************************************************************/
83185
bool AdafruitIO_Feed::save(unsigned int value, double lat, double lon,
84186
double ele) {
85187
data->setValue(value, lat, lon, ele);
86188
return _pub->publish(data->toCSV());
87189
}
88190

191+
/**************************************************************************/
192+
/*!
193+
@brief Updates Adafruit IO Feed.
194+
@param value
195+
Value to publish to feed.
196+
@param lat
197+
Latitude metadata.
198+
@param lon
199+
Longitudinal metadata.
200+
@param ele
201+
Elevation metadata.
202+
@return True if data successfully published to feed, False otherwise.
203+
*/
204+
/**************************************************************************/
89205
bool AdafruitIO_Feed::save(long value, double lat, double lon, double ele) {
90206
data->setValue(value, lat, lon, ele);
91207
return _pub->publish(data->toCSV());
92208
}
93209

210+
/**************************************************************************/
211+
/*!
212+
@brief Updates Adafruit IO Feed.
213+
@param value
214+
Value to publish to feed.
215+
@param lat
216+
Latitude metadata.
217+
@param lon
218+
Longitudinal metadata.
219+
@param ele
220+
Elevation metadata.
221+
@return True if data successfully published to feed, False otherwise.
222+
*/
223+
/**************************************************************************/
94224
bool AdafruitIO_Feed::save(unsigned long value, double lat, double lon,
95225
double ele) {
96226
data->setValue(value, lat, lon, ele);
97227
return _pub->publish(data->toCSV());
98228
}
99229

230+
/**************************************************************************/
231+
/*!
232+
@brief Updates Adafruit IO Feed.
233+
@param value
234+
Value to publish to feed.
235+
@param lat
236+
Latitude metadata.
237+
@param lon
238+
Longitudinal metadata.
239+
@param ele
240+
Elevation metadata.
241+
@param precision
242+
Desired amount of decimal precision.
243+
@return True if data successfully published to feed, False otherwise.
244+
*/
245+
/**************************************************************************/
100246
bool AdafruitIO_Feed::save(float value, double lat, double lon, double ele,
101247
int precision) {
102248
data->setValue(value, lat, lon, ele, precision);
103249
return _pub->publish(data->toCSV());
104250
}
105251

252+
/**************************************************************************/
253+
/*!
254+
@brief Updates Adafruit IO Feed.
255+
@param value
256+
Value to publish to feed.
257+
@param lat
258+
Latitude metadata.
259+
@param lon
260+
Longitudinal metadata.
261+
@param ele
262+
Elevation metadata.
263+
@param precision
264+
Desired amount of decimal precision.
265+
@return True if data successfully published to feed, False otherwise.
266+
*/
267+
/**************************************************************************/
106268
bool AdafruitIO_Feed::save(double value, double lat, double lon, double ele,
107269
int precision) {
108270
data->setValue(value, lat, lon, ele, precision);
109271
return _pub->publish(data->toCSV());
110272
}
111273

274+
/****************************************************************************/
275+
/*!
276+
@brief Publishes a null character to an Adafruit IO /get topic.
277+
https://io.adafruit.com/api/docs/mqtt.html#using-the-get-topic
278+
@return HTTP status code 200.
279+
*/
280+
/****************************************************************************/
112281
bool AdafruitIO_Feed::get() { return _get_pub->publish("\0"); }
113282

283+
/****************************************************************************/
284+
/*!
285+
@brief Checks if Adafruit IO Feed exists and belongs to username.
286+
https://io.adafruit.com/api/docs/#get-feed
287+
@return HTTP status code 200.
288+
*/
289+
/****************************************************************************/
114290
bool AdafruitIO_Feed::exists() {
115291
_io->_http->beginRequest();
116292
_io->_http->get(_feed_url);
@@ -123,6 +299,13 @@ bool AdafruitIO_Feed::exists() {
123299
return status == 200;
124300
}
125301

302+
/**************************************************************/
303+
/*!
304+
@brief Creates a new Adafruit IO Feed
305+
https://io.adafruit.com/api/docs/#create-feed
306+
@return HTTP status code 201.
307+
*/
308+
/*************************************************************/
126309
bool AdafruitIO_Feed::create() {
127310
String body = "name=";
128311
body += name;
@@ -149,6 +332,13 @@ bool AdafruitIO_Feed::create() {
149332
return status == 201;
150333
}
151334

335+
/*****************************************************************************/
336+
/*!
337+
@brief Retrieves the most recent value published to a feed.
338+
https://io.adafruit.com/api/docs/mqtt.html#using-the-get-topic
339+
@return NULL
340+
*/
341+
/*****************************************************************************/
152342
AdafruitIO_Data *AdafruitIO_Feed::lastValue() {
153343
// 15 extra for api path, 12 for /data/retain, 1 for null
154344
String url = "/api/v2/";
@@ -187,10 +377,30 @@ AdafruitIO_Data *AdafruitIO_Feed::lastValue() {
187377
}
188378
}
189379

380+
/**************************************************************************/
381+
/*!
382+
@brief Sets Adafruit IO feed location metadata.
383+
@param lat
384+
Latitude metadata.
385+
@param lon
386+
Longitudinal metadata.
387+
@param ele
388+
Elevation metadata.
389+
*/
390+
/**************************************************************************/
190391
void AdafruitIO_Feed::setLocation(double lat, double lon, double ele) {
191392
data->setLocation(lat, lon, ele);
192393
}
193394

395+
/**************************************************************************/
396+
/*!
397+
@brief Calls _datacallback if new data is avaliable on feed.
398+
@param val
399+
Value to publish to Adafruit IO feed.
400+
@param len
401+
Feed length.
402+
*/
403+
/**************************************************************************/
194404
void AdafruitIO_Feed::subCallback(char *val, uint16_t len) {
195405
data->setCSV(val);
196406

@@ -199,6 +409,11 @@ void AdafruitIO_Feed::subCallback(char *val, uint16_t len) {
199409
_dataCallback(data);
200410
}
201411

412+
/**************************************************************************/
413+
/*!
414+
@brief Initialize MQTT topics and REST URLs for Adafruit IO feeds.
415+
*/
416+
/**************************************************************************/
202417
void AdafruitIO_Feed::_init() {
203418
_sub = 0;
204419
_pub = 0;

0 commit comments

Comments
 (0)