| .. | .. |
|---|
| 15 | 15 | import 'package:uuid/uuid.dart'; |
|---|
| 16 | 16 | |
|---|
| 17 | 17 | import '../models/server_config.dart'; |
|---|
| 18 | +import 'trace_service.dart'; |
|---|
| 18 | 19 | import 'wol_service.dart'; |
|---|
| 19 | 20 | |
|---|
| 20 | 21 | /// Connection status for the MQTT client. |
|---|
| .. | .. |
|---|
| 25 | 26 | reconnecting, |
|---|
| 26 | 27 | } |
|---|
| 27 | 28 | |
|---|
| 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. |
|---|
| 29 | 31 | Future<void> _mqttLog(String msg) async { |
|---|
| 30 | 32 | debugPrint('[MQTT] $msg'); |
|---|
| 33 | + TraceService.instance.addTrace('MQTT', msg); |
|---|
| 31 | 34 | if (!kDebugMode) return; |
|---|
| 32 | 35 | try { |
|---|
| 33 | 36 | final dir = await pp.getApplicationDocumentsDirectory(); |
|---|
| .. | .. |
|---|
| 490 | 493 | // Dedup by msgId |
|---|
| 491 | 494 | final msgId = json['msgId'] as String?; |
|---|
| 492 | 495 | 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 | + } |
|---|
| 494 | 505 | _seenMsgIds.add(msgId); |
|---|
| 495 | 506 | _seenMsgIdOrder.add(msgId); |
|---|
| 496 | 507 | _evictOldIds(); |
|---|
| 497 | 508 | } |
|---|
| 498 | 509 | |
|---|
| 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 | + |
|---|
| 499 | 517 | // Dispatch: parse topic to enrich the message with routing info |
|---|
| 500 | 518 | _dispatchMessage(msg.topic, json); |
|---|
| 501 | 519 | } |
|---|