Skip to content

Commit 0daa4e1

Browse files
authored
Merge pull request #13 from adafruit/httpclient
ArduinoHttpClient v0.2.0 support
2 parents c2ddc40 + be713aa commit 0daa4e1

File tree

4 files changed

+62
-20
lines changed

4 files changed

+62
-20
lines changed

src/AdafruitIO_Dashboard.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ bool AdafruitIO_Dashboard::exists()
2727
url += "/dashboards/";
2828
url += name;
2929

30-
_io->_http->startRequest(url.c_str(), HTTP_METHOD_GET);
30+
_io->_http->beginRequest();
31+
_io->_http->get(url.c_str());
3132
_io->_http->sendHeader("X-AIO-Key", _io->_key);
3233
_io->_http->endRequest();
3334

@@ -46,12 +47,21 @@ bool AdafruitIO_Dashboard::create()
4647
String body = "name=";
4748
body += name;
4849

49-
_io->_http->startRequest(url.c_str(), HTTP_METHOD_POST);
50-
_io->_http->sendHeader(HTTP_HEADER_CONTENT_TYPE, "application/x-www-form-urlencoded");
51-
_io->_http->sendHeader(HTTP_HEADER_CONTENT_LENGTH, body.length());
50+
_io->_http->beginRequest();
51+
_io->_http->post(url.c_str());
52+
53+
_io->_http->sendHeader("Content-Type", "application/x-www-form-urlencoded");
54+
_io->_http->sendHeader("Content-Length", body.length());
5255
_io->_http->sendHeader("X-AIO-Key", _io->_key);
56+
57+
// the following call to endRequest
58+
// should be replaced by beginBody once the
59+
// Arduino HTTP Client Library is updated
60+
// _io->_http->beginBody();
61+
_io->_http->endRequest();
62+
63+
_io->_http->print(body);
5364
_io->_http->endRequest();
54-
_io->_http->write((const byte*)body.c_str(), body.length());
5565

5666
int status = _io->_http->responseStatusCode();
5767
_io->_http->responseBody(); // needs to be read even if not used

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

src/blocks/AdafruitIO_Block.cpp

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,21 @@ bool AdafruitIO_Block::save()
7575
body += block_feeds;
7676
body += "}";
7777

78-
http->startRequest(url.c_str(), HTTP_METHOD_POST);
79-
http->sendHeader(HTTP_HEADER_CONTENT_TYPE, "application/json");
80-
http->sendHeader(HTTP_HEADER_CONTENT_LENGTH, body.length());
78+
http->beginRequest();
79+
http->post(url.c_str());
80+
81+
http->sendHeader("Content-Type", "application/json");
82+
http->sendHeader("Content-Length", body.length());
8183
http->sendHeader("X-AIO-Key", _dashboard->io()->_key);
84+
85+
// the following call to endRequest
86+
// should be replaced by beginBody once the
87+
// Arduino HTTP Client Library is updated
88+
// http->beginBody();
89+
http->endRequest();
90+
91+
http->print(body);
8292
http->endRequest();
83-
http->write((const byte*)body.c_str(), body.length());
8493

8594
int status = http->responseStatusCode();
8695
http->responseBody(); // needs to be read even if not used

0 commit comments

Comments
 (0)