networking broken

This commit is contained in:
2026-02-13 20:15:53 -08:00
parent 86b94e3781
commit 6c4cfd3a45

View File

@@ -23,7 +23,7 @@
// ===================================================================== // =====================================================================
// DEBUG MODE — set to true to use _test topic suffix // DEBUG MODE — set to true to use _test topic suffix
// ===================================================================== // =====================================================================
#define DEBUG_MODE 1 #define DEBUG_MODE 0
// ===================================================================== // =====================================================================
// WiFi // WiFi
@@ -51,7 +51,7 @@ WiFiMulti wifiMulti;
#define SILENCE_URL NTFY_BASE "/SILENCE_klubhaus_topic" TOPIC_SUFFIX "/json?since=10s&poll=1" #define SILENCE_URL NTFY_BASE "/SILENCE_klubhaus_topic" TOPIC_SUFFIX "/json?since=10s&poll=1"
#define ADMIN_URL NTFY_BASE "/ADMIN_klubhaus_topic" TOPIC_SUFFIX "/json?since=10s&poll=1" #define ADMIN_URL NTFY_BASE "/ADMIN_klubhaus_topic" TOPIC_SUFFIX "/json?since=10s&poll=1"
#define STATUS_URL NTFY_BASE "/STATUS_klubhaus_topic" TOPIC_SUFFIX #define STATUS_URL NTFY_BASE "/STATUS_klubhaus_topic" TOPIC_SUFFIX
//
// ===================================================================== // =====================================================================
// Timing // Timing
// ===================================================================== // =====================================================================
@@ -226,7 +226,6 @@ bool pendingStatus = false;
String pendingStatusState = ""; String pendingStatusState = "";
String pendingStatusMsg = ""; String pendingStatusMsg = "";
// HTTPClient http;
// ===================================================================== // =====================================================================
// Drawing Helpers // Drawing Helpers
@@ -367,6 +366,7 @@ void flushStatus() {
client.setInsecure(); client.setInsecure();
HTTPClient statusHttp; HTTPClient statusHttp;
statusHttp.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
statusHttp.begin(client, 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);
@@ -377,7 +377,6 @@ void flushStatus() {
pendingStatusState = ""; pendingStatusState = "";
pendingStatusMsg = ""; pendingStatusMsg = "";
} }
// ===================================================================== // =====================================================================
// Message Parsing — per-topic dedup // Message Parsing — per-topic dedup
// ===================================================================== // =====================================================================
@@ -441,28 +440,55 @@ void parseMessages(String &response, const char *topicName,
} }
// ===================================================================== // =====================================================================
// ntfy Polling — with TLS support // ntfy Polling — with diagnostics and proper HTTPS
// ===================================================================== // =====================================================================
#include <WiFiClientSecure.h> #include <WiFiClientSecure.h>
bool networkOK = false;
void checkNetwork() {
Serial.printf("[NET] WiFi: %s RSSI: %d IP: %s GW: %s DNS: %s\n",
WiFi.SSID().c_str(),
WiFi.RSSI(),
WiFi.localIP().toString().c_str(),
WiFi.gatewayIP().toString().c_str(),
WiFi.dnsIP().toString().c_str());
Serial.flush();
// Test DNS resolution
IPAddress ip;
if (WiFi.hostByName("ntfy.sh", ip)) {
Serial.printf("[NET] ntfy.sh resolved to %s\n", ip.toString().c_str());
networkOK = true;
} else {
Serial.println("[NET] *** DNS FAILED for ntfy.sh ***");
networkOK = false;
}
Serial.flush();
}
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)
{ {
WiFiClientSecure client; WiFiClientSecure client;
client.setInsecure(); // skip cert verification for ntfy.sh client.setInsecure();
HTTPClient http; HTTPClient http;
http.begin(client, url); http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
http.setTimeout(10000); http.setTimeout(10000);
http.begin(client, url);
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) { } else if (code > 0) {
Serial.printf("[%s] HTTP error: %s\n", topicName, http.errorToString(code).c_str()); Serial.printf("[%s] HTTP %d\n", topicName, code);
} else {
Serial.printf("[%s] Error: %s\n", topicName, http.errorToString(code).c_str());
} }
http.end(); http.end();
} }
@@ -665,6 +691,7 @@ void setup() {
delay(1500); delay(1500);
connectWiFi(); connectWiFi();
if (WiFi.isConnected()) checkNetwork();
timeClient.begin(); timeClient.begin();
if (timeClient.update()) { if (timeClient.update()) {
@@ -716,15 +743,19 @@ void loop() {
} }
} }
// Poll ntfy.sh // Poll ntfy.sh
if (now - lastPoll >= POLL_INTERVAL_MS) { if (now - lastPoll >= POLL_INTERVAL_MS) {
lastPoll = now; lastPoll = now;
if (WiFi.isConnected() && ntpSynced) { if (WiFi.isConnected() && ntpSynced) {
pollTopic(ALERT_URL, handleAlertMessage, "ALERT", lastAlertId); if (!networkOK) checkNetwork(); // diagnose on first poll
pollTopic(SILENCE_URL, handleSilenceMessage, "SILENCE", lastSilenceId); pollTopic(ALERT_URL, handleAlertMessage, "ALERT", lastAlertId);
pollTopic(ADMIN_URL, handleAdminMessage, "ADMIN", lastAdminId); pollTopic(SILENCE_URL, handleSilenceMessage, "SILENCE", lastSilenceId);
} pollTopic(ADMIN_URL, handleAdminMessage, "ADMIN", lastAdminId);
} }
}
// Send any queued status AFTER polling connections are closed
flushStatus();
switch (currentState) { switch (currentState) {
case STATE_ALERTING: case STATE_ALERTING: