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
// =====================================================================
#define DEBUG_MODE 1
#define DEBUG_MODE 0
// =====================================================================
// WiFi
@@ -51,7 +51,7 @@ WiFiMulti wifiMulti;
#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 STATUS_URL NTFY_BASE "/STATUS_klubhaus_topic" TOPIC_SUFFIX
//
// =====================================================================
// Timing
// =====================================================================
@@ -226,7 +226,6 @@ bool pendingStatus = false;
String pendingStatusState = "";
String pendingStatusMsg = "";
// HTTPClient http;
// =====================================================================
// Drawing Helpers
@@ -367,6 +366,7 @@ void flushStatus() {
client.setInsecure();
HTTPClient statusHttp;
statusHttp.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
statusHttp.begin(client, STATUS_URL);
statusHttp.addHeader("Content-Type", "application/json");
int code = statusHttp.POST(payload);
@@ -377,7 +377,6 @@ void flushStatus() {
pendingStatusState = "";
pendingStatusMsg = "";
}
// =====================================================================
// 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>
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 (*handler)(const String&),
const char *topicName,
String &lastId)
{
WiFiClientSecure client;
client.setInsecure(); // skip cert verification for ntfy.sh
client.setInsecure();
HTTPClient http;
http.begin(client, url);
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
http.setTimeout(10000);
http.begin(client, url);
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 error: %s\n", topicName, http.errorToString(code).c_str());
} 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());
}
http.end();
}
@@ -665,6 +691,7 @@ void setup() {
delay(1500);
connectWiFi();
if (WiFi.isConnected()) checkNetwork();
timeClient.begin();
if (timeClient.update()) {
@@ -716,15 +743,19 @@ void loop() {
}
}
// Poll ntfy.sh
if (now - lastPoll >= POLL_INTERVAL_MS) {
lastPoll = now;
if (WiFi.isConnected() && ntpSynced) {
pollTopic(ALERT_URL, handleAlertMessage, "ALERT", lastAlertId);
pollTopic(SILENCE_URL, handleSilenceMessage, "SILENCE", lastSilenceId);
pollTopic(ADMIN_URL, handleAdminMessage, "ADMIN", lastAdminId);
}
// Poll ntfy.sh
if (now - lastPoll >= POLL_INTERVAL_MS) {
lastPoll = now;
if (WiFi.isConnected() && ntpSynced) {
if (!networkOK) checkNetwork(); // diagnose on first poll
pollTopic(ALERT_URL, handleAlertMessage, "ALERT", lastAlertId);
pollTopic(SILENCE_URL, handleSilenceMessage, "SILENCE", lastSilenceId);
pollTopic(ADMIN_URL, handleAdminMessage, "ADMIN", lastAdminId);
}
}
// Send any queued status AFTER polling connections are closed
flushStatus();
switch (currentState) {
case STATE_ALERTING: