This commit is contained in:
2026-02-13 20:06:57 -08:00
parent da2a077343
commit 86b94e3781

View File

@@ -18,6 +18,7 @@
#include <NTPClient.h> #include <NTPClient.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#include <Arduino_GFX_Library.h> #include <Arduino_GFX_Library.h>
#include <WiFiClientSecure.h>
// ===================================================================== // =====================================================================
// DEBUG MODE — set to true to use _test topic suffix // DEBUG MODE — set to true to use _test topic suffix
@@ -225,7 +226,7 @@ bool pendingStatus = false;
String pendingStatusState = ""; String pendingStatusState = "";
String pendingStatusMsg = ""; String pendingStatusMsg = "";
HTTPClient http; // HTTPClient http;
// ===================================================================== // =====================================================================
// Drawing Helpers // Drawing Helpers
@@ -362,15 +363,17 @@ void flushStatus() {
String payload; String payload;
serializeJson(doc, payload); serializeJson(doc, payload);
WiFiClientSecure client;
client.setInsecure();
HTTPClient statusHttp; HTTPClient statusHttp;
statusHttp.begin(STATUS_URL); statusHttp.begin(client, STATUS_URL);
statusHttp.addHeader("Content-Type", "application/json"); statusHttp.addHeader("Content-Type", "application/json");
int code = statusHttp.POST(payload); int code = statusHttp.POST(payload);
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());
// Free memory immediately
pendingStatusState = ""; pendingStatusState = "";
pendingStatusMsg = ""; pendingStatusMsg = "";
} }
@@ -438,24 +441,31 @@ void parseMessages(String &response, const char *topicName,
} }
// ===================================================================== // =====================================================================
// ntfy Polling // ntfy Polling — with TLS support
// ===================================================================== // =====================================================================
#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,
String &lastId) String &lastId)
{ {
http.begin(url); WiFiClientSecure client;
client.setInsecure(); // skip cert verification for ntfy.sh
HTTPClient http;
http.begin(client, url);
http.setTimeout(10000); http.setTimeout(10000);
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 error: %s\n", topicName, http.errorToString(code).c_str());
} }
http.end(); http.end();
} }
// ===================================================================== // =====================================================================
// Message Handlers // Message Handlers
// ===================================================================== // =====================================================================
@@ -680,8 +690,10 @@ void loop() {
String cmd = Serial.readStringUntil('\n'); String cmd = Serial.readStringUntil('\n');
cmd.trim(); cmd.trim();
if (cmd == "CLEAR_DEDUP") { if (cmd == "CLEAR_DEDUP") {
lastProcessedId = ""; lastAlertId = "";
Serial.println("[CMD] Dedup cleared"); lastSilenceId = "";
lastAdminId = "";
Serial.println("[CMD] Dedup cleared (all topics)");
} }
} }