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(); statusHttp.end();
Serial.printf("[STATUS] Sent (%d): %s\n", code, pendingStatusState.c_str()); Serial.printf("[STATUS] Sent (%d): %s\n", code, pendingStatusState.c_str());
pendingStatusState = ""; pendingStatusState = "";
pendingStatusMsg = ""; pendingStatusMsg = "";
} }
@@ -490,6 +489,8 @@ void checkNetwork() {
Serial.flush(); Serial.flush();
} }
#include <WiFiClientSecure.h>
void pollTopic(const char *url, void pollTopic(const char *url,
void (*handler)(const String&), void (*handler)(const String&),
const char *topicName, const char *topicName,
@@ -501,17 +502,20 @@ void pollTopic(const char *url,
HTTPClient http; HTTPClient http;
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS); http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
http.setTimeout(10000); http.setTimeout(10000);
http.begin(client, url);
if (!http.begin(client, url)) {
Serial.printf("[%s] begin() failed\n", topicName);
return;
}
int code = http.GET(); int code = http.GET();
if (code == HTTP_CODE_OK) { if (code == HTTP_CODE_OK) {
String response = http.getString(); String response = http.getString();
if (response.length() > 0) if (response.length() > 0)
parseMessages(response, topicName, handler, lastId); parseMessages(response, topicName, handler, lastId);
} else if (code > 0) {
Serial.printf("[%s] HTTP %d\n", topicName, code);
} else { } 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(); http.end();
} }