Skip to content

Commit

Permalink
outside status check
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr committed Sep 15, 2019
1 parent 408155a commit 846af75
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
8 changes: 4 additions & 4 deletions code/espurna/libs/Http.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class AsyncHttp {
};

using on_connected_f = std::function<void(AsyncHttp*)>;
using on_status_f = std::function<void(AsyncHttp*, uint16_t status)>;
using on_status_f = std::function<bool(AsyncHttp*, uint16_t status)>;
using on_disconnected_f = std::function<void(AsyncHttp*)>;
using on_error_f = std::function<void(AsyncHttp*, const AsyncHttpError&)>;
using on_body_f = std::function<void(AsyncHttp*, uint8_t*, size_t)>;
Expand Down Expand Up @@ -174,9 +174,8 @@ class AsyncHttp {
ASYNC_HTTP_DEBUG("log | buf code=%s\n", buf);

unsigned int code = atoi(buf);
if (code != 200) { // 200 OK
ASYNC_HTTP_DEBUG("err | http code=%u\n", code);
if (http->on_status) http->on_status(http, code);
ASYNC_HTTP_DEBUG("info | http code=%u\n", code);
if (http->on_status && !http->on_status(http, code)) {
return;
}

Expand Down Expand Up @@ -258,6 +257,7 @@ class AsyncHttp {

client->write(headers.get());
client->write(http->data.c_str());

}

public:
Expand Down
11 changes: 6 additions & 5 deletions code/espurna/ota_asynctcp.ino
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ void _otaOnError(AsyncHttp* http, const AsyncHttpError& error) {
}
}

void _otaOnStatus(AsyncHttp* http, const unsigned int code) {
if (code != 200) {
DEBUG_MSG_P(PSTR("[OTA] HTTP server response code %u\n"), code);
http->client.close(true);
}
bool _otaOnStatus(AsyncHttp* http, const unsigned int code) {
if (code == 200) return true;

DEBUG_MSG_P(PSTR("[OTA] HTTP server response code %u\n"), code);
http->client.close(true);
return false;
}

void _otaClientOnBody(AsyncHttp* http, uint8_t* data, size_t len) {
Expand Down
11 changes: 6 additions & 5 deletions code/espurna/thinkspeak.ino
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,12 @@ void _tspkOnDisconnected(AsyncHttp* http) {
if (_tspk_tries) --_tspk_tries;
}

void _tspkOnStatus(AsyncHttp* http, const unsigned int code) {
if (code != 200) {
DEBUG_MSG_P(PSTR("[THINGSPEAK] HTTP server response code %u\n"), code);
http->client.close(true);
}
bool _tspkOnStatus(AsyncHttp* http, const unsigned int code) {
if (code == 200) return true;

DEBUG_MSG_P(PSTR("[THINGSPEAK] HTTP server response code %u\n"), code);
http->client.close(true);
return false;
}

void _tspkOnError(AsyncHttp* http, const AsyncHttpError& error) {
Expand Down

0 comments on commit 846af75

Please sign in to comment.