diff --git a/sketches/doorbell-touch/doorbell-touch.ino b/sketches/doorbell-touch/doorbell-touch.ino index abfea3f..c3bbc40 100644 --- a/sketches/doorbell-touch/doorbell-touch.ino +++ b/sketches/doorbell-touch/doorbell-touch.ino @@ -374,7 +374,6 @@ void flushStatus() { statusHttp.end(); Serial.printf("[STATUS] Sent (%d): %s\n", code, pendingStatusState.c_str()); - pendingStatusState = ""; pendingStatusMsg = ""; } @@ -490,6 +489,8 @@ void checkNetwork() { Serial.flush(); } +#include + void pollTopic(const char *url, void (*handler)(const String&), const char *topicName, @@ -501,17 +502,20 @@ void pollTopic(const char *url, HTTPClient http; http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); http.setTimeout(10000); - http.begin(client, url); + + if (!http.begin(client, url)) { + Serial.printf("[%s] begin() failed\n", topicName); + return; + } int code = http.GET(); if (code == HTTP_CODE_OK) { String response = http.getString(); if (response.length() > 0) parseMessages(response, topicName, handler, lastId); - } else if (code > 0) { - Serial.printf("[%s] HTTP %d\n", topicName, code); } else { - Serial.printf("[%s] Error: %s\n", topicName, http.errorToString(code).c_str()); + Serial.printf("[%s] HTTP %d: %s\n", topicName, code, + code < 0 ? http.errorToString(code).c_str() : ""); } http.end(); }