Skip to content

Commit de055ce

Browse files
committed
update feed & group http client calls
1 parent 843682a commit de055ce

File tree

2 files changed

+34
-11
lines changed

2 files changed

+34
-11
lines changed

src/AdafruitIO_Feed.cpp

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,14 @@ bool AdafruitIO_Feed::save(double value, double lat, double lon, double ele, int
105105

106106
bool AdafruitIO_Feed::exists()
107107
{
108-
_io->_http->startRequest(_feed_url, HTTP_METHOD_GET);
108+
_io->_http->beginRequest();
109+
_io->_http->get(_feed_url);
109110
_io->_http->sendHeader("X-AIO-Key", _io->_key);
110111
_io->_http->endRequest();
112+
111113
int status = _io->_http->responseStatusCode();
112114
_io->_http->responseBody(); // needs to be read even if not used
115+
113116
return status == 200;
114117
}
115118

@@ -118,15 +121,25 @@ bool AdafruitIO_Feed::create()
118121
String body = "name=";
119122
body += name;
120123

121-
_io->_http->startRequest(_create_url, HTTP_METHOD_POST);
122-
_io->_http->sendHeader(HTTP_HEADER_CONTENT_TYPE, "application/x-www-form-urlencoded");
123-
_io->_http->sendHeader(HTTP_HEADER_CONTENT_LENGTH, body.length());
124+
_io->_http->beginRequest();
125+
_io->_http->post(_create_url);
126+
127+
_io->_http->sendHeader("Content-Type", "application/x-www-form-urlencoded");
128+
_io->_http->sendHeader("Content-Length", body.length());
124129
_io->_http->sendHeader("X-AIO-Key", _io->_key);
130+
131+
// the following call to endRequest
132+
// should be replaced by beginBody once the
133+
// Arduino HTTP Client Library is updated
134+
// _io->_http->beginBody();
135+
_io->_http->endRequest();
136+
137+
_io->_http->print(body);
125138
_io->_http->endRequest();
126-
_io->_http->write((const byte*)body.c_str(), body.length());
127139

128140
int status = _io->_http->responseStatusCode();
129141
_io->_http->responseBody(); // needs to be read even if not used
142+
130143
return status == 201;
131144
}
132145

src/AdafruitIO_Group.cpp

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,11 @@ void AdafruitIO_Group::setLocation(double lat, double lon, double ele)
283283

284284
bool AdafruitIO_Group::exists()
285285
{
286-
_io->_http->startRequest(_group_url, HTTP_METHOD_GET);
286+
_io->_http->beginRequest();
287+
_io->_http->get(_group_url);
287288
_io->_http->sendHeader("X-AIO-Key", _io->_key);
288289
_io->_http->endRequest();
290+
289291
int status = _io->_http->responseStatusCode();
290292
_io->_http->responseBody(); // needs to be read even if not used
291293
return status == 200;
@@ -296,19 +298,27 @@ bool AdafruitIO_Group::create()
296298
String body = "name=";
297299
body += name;
298300

299-
_io->_http->startRequest(_create_url, HTTP_METHOD_POST);
300-
_io->_http->sendHeader(HTTP_HEADER_CONTENT_TYPE, "application/x-www-form-urlencoded");
301-
_io->_http->sendHeader(HTTP_HEADER_CONTENT_LENGTH, body.length());
301+
_io->_http->beginRequest();
302+
_io->_http->post(_create_url);
303+
304+
_io->_http->sendHeader("Content-Type", "application/x-www-form-urlencoded");
305+
_io->_http->sendHeader("Content-Length", body.length());
302306
_io->_http->sendHeader("X-AIO-Key", _io->_key);
307+
308+
// the following call to endRequest
309+
// should be replaced by beginBody once the
310+
// Arduino HTTP Client Library is updated
311+
// _io->_http->beginBody();
312+
_io->_http->endRequest();
313+
314+
_io->_http->print(body);
303315
_io->_http->endRequest();
304-
_io->_http->write((const byte*)body.c_str(), body.length());
305316

306317
int status = _io->_http->responseStatusCode();
307318
_io->_http->responseBody(); // needs to be read even if not used
308319
return status == 201;
309320
}
310321

311-
312322
void AdafruitIO_Group::_init()
313323
{
314324

0 commit comments

Comments
 (0)