Skip to content

Commit 7fff1c7

Browse files
author
Alex J Lennon
committed
v1.4.0: Default DEBUG logging, MQTT improvements, and health check integration
- Changed default LogLevel to Debug in appsettings.json for testing - Added process ID to MQTT client ID for uniqueness when multiple instances run - Added DEBUG-level logging for JSON payloads being published - Added DEBUG-level logging for detailed node information when receiving messages - Configured MQTT KeepAlive period (60s) to prevent broker disconnections - Integrated health check metrics (process time, beacon count, nodes processed, MQTT status) - Fixed average error calculation in UWB2GPSConverter (now calculates true mean linear error) - Added detailed logging for worst edge errors to help debug discrepancies
1 parent 77e44f2 commit 7fff1c7

File tree

8 files changed

+87
-16
lines changed

8 files changed

+87
-16
lines changed

PROJECT_CONTEXT.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@
66

77
**Status**: Active Development
88
**Last Updated**: 2025-11-14
9-
**Version**: 1.3.0
10-
**Latest Release**: [v1.3.0](https://github.com/DynamicDevices/cga-coordinate-mapping/releases/tag/v1.3.0) (2025-11-14)
9+
**Version**: 1.4.0
10+
**Latest Release**: [v1.4.0](https://github.com/DynamicDevices/cga-coordinate-mapping/releases/tag/v1.4.0) (2025-11-14)
1111
**Repository**: `[email protected]:DynamicDevices/cga-coordinate-mapping.git`
1212
**License**: GPLv3 (see LICENSE file)
1313

1414
## Recent Updates (2025-11-14)
1515

16+
### Debug Logging Default & MQTT Improvements (2025-11-14 - v1.4.0)
17+
-**Default DEBUG Logging**: Changed default `LogLevel` in `appsettings.json` from "Information" to "Debug" for testing
18+
-**MQTT Client ID Uniqueness**: Added process ID to MQTT client ID to prevent conflicts when multiple instances run on same hardware
19+
-**DEBUG JSON Payload Logging**: Added DEBUG-level logging for full JSON payloads being published to MQTT
20+
-**DEBUG Node Data Logging**: Added DEBUG-level logging for detailed node information (positionKnown, latLonAlt, edges) when receiving MQTT messages
21+
-**MQTT KeepAlive**: Configured MQTT KeepAlive period (60s default) to prevent broker from disconnecting idle clients
22+
-**Health Check Integration**: Integrated health check metrics (last process time, beacon count, nodes processed, MQTT connection status)
23+
1624
### Critical CI Fix (2025-11-14 - v1.3.0)
1725
-**FIXED CI**: Removed `Directory.Build.props` that was causing shared obj directory conflicts
1826
-**Root Cause Resolved**: Each project now has separate obj/bin directories

src/InstDotNet.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
<Nullable>enable</Nullable>
1515

1616
<!-- Semantic Versioning -->
17-
<Version>1.3.0</Version>
18-
<AssemblyVersion>1.3.0.0</AssemblyVersion>
19-
<FileVersion>1.3.0.0</FileVersion>
20-
<VersionPrefix>1.3.0</VersionPrefix>
17+
<Version>1.4.0</Version>
18+
<AssemblyVersion>1.4.0.0</AssemblyVersion>
19+
<FileVersion>1.4.0.0</FileVersion>
20+
<VersionPrefix>1.4.0</VersionPrefix>
2121
<VersionSuffix></VersionSuffix>
2222

2323
<!-- Build metadata -->

src/MQTTControl.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,12 @@ public static async Task Initialise(CancellationTokenSource cts, AppConfig? conf
6060
if (string.IsNullOrWhiteSpace(config.MQTT.ClientId) ||
6161
config.MQTT.ClientId == DEFAULT_CLIENT_ID)
6262
{
63-
_clientId = HardwareId.GetMqttClientId("UwbManager");
64-
_logger?.LogInformation("Using hardware-based MQTT client ID: {ClientId}", _clientId);
63+
// Add process ID to make client ID unique per instance
64+
// This prevents conflicts when multiple instances run on the same hardware
65+
var baseClientId = HardwareId.GetMqttClientId("UwbManager");
66+
var processId = System.Diagnostics.Process.GetCurrentProcess().Id;
67+
_clientId = $"{baseClientId}-pid{processId}";
68+
_logger?.LogInformation("Using hardware-based MQTT client ID: {ClientId} (PID: {ProcessId})", _clientId, processId);
6569
}
6670
else
6771
{

src/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ static async Task Main()
3232

3333
// Display version information
3434
logger.LogInformation("CGA Coordinate Mapping - {Version}", VersionInfo.FullVersion);
35-
logger.LogInformation("Log level: {LogLevel}", logLevel);
35+
logger.LogInformation("Log level: {LogLevel} (from config: '{ConfigValue}')", logLevel, logLevelString ?? "null");
3636
logger.LogInformation("Configuration loaded: {BeaconCount} beacons configured", _config.Beacons.Count);
3737
logger.LogInformation("");
3838

src/UWB2GPSConverter.cs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ public static void ConvertUWBToPositions(Network network, bool refine, Algorithm
359359
int totalEdges = 0;
360360
float maxError = 0;
361361
float minError = float.MaxValue;
362+
string? maxErrorEdge = null;
363+
string? minErrorEdge = null;
364+
float maxMeasuredDist = 0;
365+
float maxCalculatedDist = 0;
362366

363367
foreach (UWB node in network.uwbs)
364368
{
@@ -370,8 +374,19 @@ public static void ConvertUWBToPositions(Network network, bool refine, Algorithm
370374
float error = Math.Abs(currentDist - edge.distance);
371375
totalError += error;
372376
totalEdges++;
373-
if (error > maxError) maxError = error;
374-
if (error < minError) minError = error;
377+
378+
if (error > maxError)
379+
{
380+
maxError = error;
381+
maxErrorEdge = $"{node.id}->{end.id}";
382+
maxMeasuredDist = edge.distance;
383+
maxCalculatedDist = currentDist;
384+
}
385+
if (error < minError)
386+
{
387+
minError = error;
388+
minErrorEdge = $"{node.id}->{end.id}";
389+
}
375390
}
376391
}
377392
}
@@ -380,6 +395,24 @@ public static void ConvertUWBToPositions(Network network, bool refine, Algorithm
380395

381396
_logger?.LogInformation("UWB to GPS conversion completed. Updated {Updated}/{Total} positions. Average error: {Error:F2}m (min: {Min:F2}m, max: {Max:F2}m, edges: {Edges}).",
382397
totalNodesUpdated, totalNodes, averageError, minError == float.MaxValue ? 0 : minError, maxError, totalEdges);
398+
399+
// Log details about the worst edge for debugging
400+
if (maxErrorEdge != null && maxError > 10.0f)
401+
{
402+
// Find the actual nodes for the worst edge to log their positions
403+
string[] edgeParts = maxErrorEdge.Split("->");
404+
if (edgeParts.Length == 2 && nodeMap.TryGetValue(edgeParts[0], out UWB? node1) && nodeMap.TryGetValue(edgeParts[1], out UWB? node2))
405+
{
406+
_logger?.LogWarning("Worst edge error: {Edge} - Measured: {Measured:F2}m, Calculated: {Calculated:F2}m, Error: {Error:F2}m",
407+
maxErrorEdge, maxMeasuredDist, maxCalculatedDist, maxError);
408+
_logger?.LogWarning(" Node1 ({Id}) position: ({X:F2}, {Y:F2}, {Z:F2}), known: {Known}, latLonAlt: {LatLonAlt}",
409+
node1.id, node1.position.X, node1.position.Y, node1.position.Z, node1.positionKnown,
410+
node1.latLonAlt != null && node1.latLonAlt.Length >= 3 ? $"{node1.latLonAlt[0]:F6}, {node1.latLonAlt[1]:F6}, {node1.latLonAlt[2]:F2}" : "null");
411+
_logger?.LogWarning(" Node2 ({Id}) position: ({X:F2}, {Y:F2}, {Z:F2}), known: {Known}, latLonAlt: {LatLonAlt}",
412+
node2.id, node2.position.X, node2.position.Y, node2.position.Z, node2.positionKnown,
413+
node2.latLonAlt != null && node2.latLonAlt.Length >= 3 ? $"{node2.latLonAlt[0]:F6}, {node2.latLonAlt[1]:F6}, {node2.latLonAlt[2]:F2}" : "null");
414+
}
415+
}
383416
if (totalNodesUpdated + 3 < totalNodes)
384417
{
385418
var untriangulatedNodes = new List<string>();

src/UWBManager.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,28 @@ public static void UpdateUwbsFromMessage(string message)
6666
if (network != null && network.uwbs != null)
6767
{
6868
_logger?.LogInformation("Successfully parsed MQTT message into UWB network. Found {Count} UWBs.", network.uwbs.Length);
69+
70+
// Log detailed node information at DEBUG level
71+
foreach (var node in network.uwbs)
72+
{
73+
if (node != null)
74+
{
75+
string latLonAltStr = node.latLonAlt != null && node.latLonAlt.Length >= 3
76+
? $"{node.latLonAlt[0]:F6}, {node.latLonAlt[1]:F6}, {node.latLonAlt[2]:F2}"
77+
: "null";
78+
79+
string edgeInfo = node.edges != null && node.edges.Count > 0
80+
? string.Join(", ", node.edges.Select(e => {
81+
// Determine which end is the other node (not the current node)
82+
string otherEnd = (e.end0 == node.id) ? e.end1 : e.end0;
83+
return $"{otherEnd}:{e.distance:F2}m";
84+
}))
85+
: "no edges";
86+
87+
_logger?.LogDebug(" Node {Id}: positionKnown={Known}, latLonAlt=[{LatLonAlt}], edges=[{Edges}]",
88+
node.id, node.positionKnown, latLonAltStr, edgeInfo);
89+
}
90+
}
6991
}
7092
updateNetworkTrigger = true;
7193
}
@@ -145,6 +167,10 @@ private static void SendNetwork(UWB2GPSConverter.Network sendNetwork)
145167
return;
146168
}
147169
string data = JsonSerializer.Serialize(sendNetwork, jsonOptions);
170+
171+
// Log the JSON payload at DEBUG level
172+
_logger?.LogDebug("Publishing JSON payload to MQTT: {JsonPayload}", data);
173+
148174
_ = Task.Run(async () => await MQTTControl.Publish(data));
149175
}
150176
}

src/VersionInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ private static string GetBuildDate()
5454
if (!string.IsNullOrEmpty(location))
5555
{
5656
var fileInfo = new FileInfo(location);
57-
return fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss UTC");
57+
return fileInfo.LastWriteTime.ToString("yyyy-MM-dd HH:mm:ss UTC");
5858
}
5959
}
60-
}
61-
catch
62-
{
60+
}
61+
catch
62+
{
6363
// Ignore - single-file app or other error
6464
}
6565
}

src/appsettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
},
2222
"Application": {
2323
"UpdateIntervalMs": 10,
24-
"LogLevel": "Information",
24+
"LogLevel": "Debug",
2525
"HealthCheckPort": 8080
2626
},
2727
"Algorithm": {

0 commit comments

Comments
 (0)