Add pulse-by-pulse and MQTT publish logging
This commit is contained in:
+16
-5
@@ -135,11 +135,14 @@ static void saveConfig() {
|
|||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
static void mqttPublishDialed(const String& number) {
|
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];
|
char topic[128];
|
||||||
snprintf(topic, sizeof(topic), "%s/dialed", mqttCfg.prefix);
|
snprintf(topic, sizeof(topic), "%s/dialed", mqttCfg.prefix);
|
||||||
mqttClient.publish(topic, number.c_str(), false); // not retained — it's an event
|
bool ok = mqttClient.publish(topic, number.c_str(), false); // not retained — it's an event
|
||||||
Serial.printf("[DIAL] published %s -> %s\n", topic, number.c_str());
|
Serial.printf("[DIAL] publish %s -> %s ok=%d\n", topic, number.c_str(), ok);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mqttCallback(char* topic, byte* payload, unsigned int len) {
|
static void mqttCallback(char* topic, byte* payload, unsigned int len) {
|
||||||
@@ -254,6 +257,7 @@ static void mqttLoop() {
|
|||||||
|
|
||||||
static void dialLoop() {
|
static void dialLoop() {
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
|
static int lastLoggedPulses = 0;
|
||||||
|
|
||||||
// Snapshot volatile state atomically
|
// Snapshot volatile state atomically
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
@@ -261,22 +265,29 @@ static void dialLoop() {
|
|||||||
unsigned long lastPulse = dialLastPulse;
|
unsigned long lastPulse = dialLastPulse;
|
||||||
interrupts();
|
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
|
// Burst silence exceeded → digit complete
|
||||||
if (pulses > 0 && (now - lastPulse) >= INTER_PULSE_MS) {
|
if (pulses > 0 && (now - lastPulse) >= INTER_PULSE_MS) {
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
dialPulses = 0;
|
dialPulses = 0;
|
||||||
interrupts();
|
interrupts();
|
||||||
|
lastLoggedPulses = 0;
|
||||||
|
|
||||||
// 10 pulses = digit '0'; 1–9 pulses = digits '1'–'9'
|
// 10 pulses = digit '0'; 1–9 pulses = digits '1'–'9'
|
||||||
char digit = '0' + (pulses >= 10 ? 0 : pulses);
|
char digit = '0' + (pulses >= 10 ? 0 : pulses);
|
||||||
dialNumber += digit;
|
dialNumber += digit;
|
||||||
dialLastDigit = now;
|
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
|
// Number complete when no further digits arrive within the timeout
|
||||||
if (dialNumber.length() > 0 && (now - dialLastDigit) >= INTER_DIGIT_MS) {
|
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);
|
mqttPublishDialed(dialNumber);
|
||||||
dialNumber = "";
|
dialNumber = "";
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user