File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -143,6 +143,44 @@ bool AdafruitIO_Feed::create()
143143 return status == 201 ;
144144}
145145
146+ AdafruitIO_Data* AdafruitIO_Feed::lastValue ()
147+ {
148+ // 15 extra for api path, 12 for /data/retain, 1 for null
149+ String url = " /api/v2/" ;
150+ url += _io->_username ;
151+ url += " /feeds/" ;
152+ url += name;
153+ url += " /data/retain" ;
154+
155+ IO_DEBUG_PRINT (" lastValue get " );
156+ IO_DEBUG_PRINTLN (url);
157+
158+ _io->_http ->beginRequest ();
159+ _io->_http ->get (url.c_str ());
160+ _io->_http ->sendHeader (" X-AIO-Key" , _io->_key );
161+ _io->_http ->endRequest ();
162+
163+ int status = _io->_http ->responseStatusCode ();
164+ String body = _io->_http ->responseBody ();
165+
166+ if (status >= 200 && status <= 299 ) {
167+
168+ if (body.length () > 0 ) {
169+ return new AdafruitIO_Data (this , body.c_str ());
170+ }
171+
172+ } else {
173+
174+ IO_ERROR_PRINT (" error retrieving lastValue, status: " );
175+ IO_ERROR_PRINTLN (status);
176+ IO_ERROR_PRINT (" response body: " );
177+ IO_ERROR_PRINTLN (_io->_http ->responseBody ());
178+
179+ return NULL ;
180+
181+ }
182+ }
183+
146184void AdafruitIO_Feed::setLocation (double lat, double lon, double ele)
147185{
148186 data->setLocation (lat, lon, ele);
Original file line number Diff line number Diff line change @@ -47,6 +47,7 @@ class AdafruitIO_Feed : public AdafruitIO_MQTT {
4747
4848 const char *name;
4949
50+ AdafruitIO_Data *lastValue ();
5051 AdafruitIO_Data *data;
5152
5253 private:
You can’t perform that action at this time.
0 commit comments