From 5ae2321f2d687434395f317dd8e8be532fe232b4 Mon Sep 17 00:00:00 2001 From: "Adrian A. Baumann" Date: Mon, 29 Jun 2026 01:32:58 +0200 Subject: [PATCH] Add pulse-by-pulse and MQTT publish logging --- src/main.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 7ad2f38..52b7807 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -135,11 +135,14 @@ static void saveConfig() { // --------------------------------------------------------------------------- static void mqttPublishDialed(const String& number) { - if (!mqttCfg.enabled || !mqttClient.connected()) return; + if (!mqttCfg.enabled || !mqttClient.connected()) { + Serial.printf("[DIAL] MQTT unavailable, number=%s not sent\n", number.c_str()); + return; + } char topic[128]; snprintf(topic, sizeof(topic), "%s/dialed", mqttCfg.prefix); - mqttClient.publish(topic, number.c_str(), false); // not retained — it's an event - Serial.printf("[DIAL] published %s -> %s\n", topic, number.c_str()); + bool ok = mqttClient.publish(topic, number.c_str(), false); // not retained — it's an event + Serial.printf("[DIAL] publish %s -> %s ok=%d\n", topic, number.c_str(), ok); } static void mqttCallback(char* topic, byte* payload, unsigned int len) { @@ -254,6 +257,7 @@ static void mqttLoop() { static void dialLoop() { unsigned long now = millis(); + static int lastLoggedPulses = 0; // Snapshot volatile state atomically noInterrupts(); @@ -261,22 +265,29 @@ static void dialLoop() { unsigned long lastPulse = dialLastPulse; interrupts(); + // Log each new pulse as it arrives (ISR can't use Serial, so we log here) + if (pulses != lastLoggedPulses) { + Serial.printf("[DIAL] pulse #%d\n", pulses); + lastLoggedPulses = pulses; + } + // Burst silence exceeded → digit complete if (pulses > 0 && (now - lastPulse) >= INTER_PULSE_MS) { noInterrupts(); dialPulses = 0; interrupts(); + lastLoggedPulses = 0; // 10 pulses = digit '0'; 1–9 pulses = digits '1'–'9' char digit = '0' + (pulses >= 10 ? 0 : pulses); dialNumber += digit; dialLastDigit = now; - Serial.printf("[DIAL] digit=%c number_so_far=%s\n", digit, dialNumber.c_str()); + Serial.printf("[DIAL] burst end pulses=%d -> digit='%c' number_so_far=%s\n", pulses, digit, dialNumber.c_str()); } // Number complete when no further digits arrive within the timeout if (dialNumber.length() > 0 && (now - dialLastDigit) >= INTER_DIGIT_MS) { - Serial.printf("[DIAL] complete number=%s\n", dialNumber.c_str()); + Serial.printf("[DIAL] number complete=%s\n", dialNumber.c_str()); mqttPublishDialed(dialNumber); dialNumber = ""; }