feat(mqtt): Reset-Topic akzeptiert JSON-Payload {reset:true} zusaetzlich zu plain 1

This commit is contained in:
MaPaLo76 2026-02-22 20:15:39 +01:00
parent c1bd36c84f
commit 100e4b960d
2 changed files with 24 additions and 2 deletions

View File

@ -180,7 +180,27 @@ void MqttClient::onMessage(const char* topic, byte* payload, unsigned int length
// Reset-Kommando
if (strcmp(topic, MQTT_TOPIC_RESET) == 0) {
bool doReset = false;
// Plain "1" (rueckwaertskompatibel)
if (strcmp(msg, "1") == 0) {
doReset = true;
}
// JSON: {"reset":true} oder {"reset":1}
else if (msg[0] == '{') {
JsonDocument doc;
DeserializationError err = deserializeJson(doc, msg);
if (!err) {
JsonVariant v = doc["reset"];
if (!v.isNull()) {
doReset = v.as<bool>() || v.as<int>() == 1;
}
} else {
Serial.printf("[MQTT] JSON-Parse-Fehler: %s\n", err.c_str());
}
}
if (doReset) {
Serial.println("[MQTT] RESET-Kommando empfangen -> laserTracker.resetTotal()");
laserTracker.resetTotal();
}

View File

@ -288,7 +288,9 @@ pio device monitor -e test-mqtt
3. `total_min` erhoehte sich trotzdem (Gratiszeit zaehlt in NVS)
**D) Reset-Kommando via MQTT:**
1. Im MQTT Explorer auf Topic `lasercutter/reset` publishen, Payload: `1`
1. Im MQTT Explorer auf Topic `lasercutter/reset` publishen
- JSON-Payload (empfohlen): `{"reset":true}`
- Alternativ Plain: `1`
2. Serial: `[MQTT] RESET-Kommando empfangen -> laserTracker.resetTotal()`
3. Naechster Heartbeat zeigt `"total_min": "0.00"`
@ -334,7 +336,7 @@ pio device monitor -e test-mqtt
| Heartbeat alle 60 s | Topic aktualisiert sich periodisch | [x] |
| Session-Publish nach Burst | `lasercutter/session` mit Session-Daten | [x] |
| Gratis-Burst publiziert `session_s: 0` | `total_min` trotzdem erhoehiert | [ ] |
| Reset via MQTT (`lasercutter/reset` = `1`) | `total_min` springt auf 0 | [ ] |
| Reset via MQTT (`lasercutter/reset` = `{"reset":true}`) | `total_min` springt auf 0 | [ ] |
| LWT `{"online":false}` nach Verbindungsabbruch | Nach 60 s im MQTT Explorer sichtbar | [ ] |
| MQTT-Error Modul 5 bei Verbindungsverlust | `E` auf Display Modul 5 | [ ] |
| Reconnect nach WiFi-Ausfall | Automatisch nach <= 10 s | [ ] |