This commit is contained in:
2026-02-13 20:29:18 -08:00
parent ce413dc20c
commit fa6bf6fd6a

View File

@@ -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 <WiFiClientSecure.h>
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();
}