File tree Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Expand file tree Collapse file tree 2 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -143,6 +143,44 @@ bool AdafruitIO_Feed::create()
143
143
return status == 201 ;
144
144
}
145
145
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
+
146
184
void AdafruitIO_Feed::setLocation (double lat, double lon, double ele)
147
185
{
148
186
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 {
47
47
48
48
const char *name;
49
49
50
+ AdafruitIO_Data *lastValue ();
50
51
AdafruitIO_Data *data;
51
52
52
53
private:
You can’t perform that action at this time.
0 commit comments