Matthias Nott
9 days ago 8d1f94e02e927fcb80d170fc85d13a091e5dc304
lib/services/mqtt_service.dart
....@@ -15,6 +15,7 @@
1515 import 'package:uuid/uuid.dart';
1616
1717 import '../models/server_config.dart';
18
+import 'trace_service.dart';
1819 import 'wol_service.dart';
1920
2021 /// Connection status for the MQTT client.
....@@ -25,9 +26,11 @@
2526 reconnecting,
2627 }
2728
28
-// Debug log — writes to file only in debug builds, always prints via debugPrint
29
+// Debug log — writes to file only in debug builds, always prints via debugPrint.
30
+// Also adds entries to TraceService so they appear in the trace log viewer.
2931 Future<void> _mqttLog(String msg) async {
3032 debugPrint('[MQTT] $msg');
33
+ TraceService.instance.addTrace('MQTT', msg);
3134 if (!kDebugMode) return;
3235 try {
3336 final dir = await pp.getApplicationDocumentsDirectory();
....@@ -490,12 +493,27 @@
490493 // Dedup by msgId
491494 final msgId = json['msgId'] as String?;
492495 if (msgId != null) {
493
- if (_seenMsgIds.contains(msgId)) continue;
496
+ if (_seenMsgIds.contains(msgId)) {
497
+ final seq = json['seq'];
498
+ final type = json['type'] as String? ?? '?';
499
+ TraceService.instance.addTrace(
500
+ 'MQTT deduped',
501
+ 'msgId=${msgId.substring(0, 8)} type=$type seq=$seq topic=${msg.topic}',
502
+ );
503
+ continue;
504
+ }
494505 _seenMsgIds.add(msgId);
495506 _seenMsgIdOrder.add(msgId);
496507 _evictOldIds();
497508 }
498509
510
+ final seq = json['seq'];
511
+ final type = json['type'] as String? ?? '?';
512
+ TraceService.instance.addTrace(
513
+ 'MQTT received',
514
+ 'seq=$seq type=$type on ${msg.topic}',
515
+ );
516
+
499517 // Dispatch: parse topic to enrich the message with routing info
500518 _dispatchMessage(msg.topic, json);
501519 }