Documentation

fsds/bbu-camera-timestamp-fix.md

Fix Plan: Camera-Tag Matching Timestamp Issue

Problem Summary

Camera reads are not matching tag reads because the timestamps are misaligned:

  • Camera EventTimestamp: Uses blobItem.Properties.LastModified (Azure blob upload time)
  • Tag EventTimestamp: Uses RFID reader's timestamp from MQTT message
  • Match window: 5 seconds

The XML file contains AcquisitionTriggerTimestamp (actual camera capture time) but it's only stored in RawTimestamp, not used for matching.

Root Cause

DatalogicBlobProcessor.cs lines 288-289 and 353:

var blobLastModified = blobItem.Properties.LastModified?.UtcDateTime ?? DateTime.UtcNow;
var eventTimestamp = blobLastModified;  // <-- Uses blob upload time, not capture time
...
EventTimestamp = eventTimestamp,  // <-- Wrong timestamp used for matching

The AcquisitionTriggerTimestamp from XML (line 310) is captured but ignored for matching purposes.

Fix

File: engines/iot/src/Acsis.Dynaplex.Engines.Iot.Abstractions/Services/DatalogicBlobProcessor.cs

Change 1: Parse and use AcquisitionTriggerTimestamp

After extracting rawTimestamp (around line 310), parse it and use as eventTimestamp:

rawTimestamp = metadata.Element("AcquisitionTriggerTimestamp")?.Value;

// Parse acquisition timestamp if available
if (!string.IsNullOrWhiteSpace(rawTimestamp) && DateTime.TryParse(rawTimestamp, out var acquisitionTime)) {
    // Use UTC if not specified, or convert to UTC
    eventTimestamp = acquisitionTime.Kind == DateTimeKind.Unspecified
        ? DateTime.SpecifyKind(acquisitionTime, DateTimeKind.Utc)
        : acquisitionTime.ToUniversalTime();
}
// Otherwise falls back to blobLastModified (already set)

Additional Issues Found (Already Fixed Earlier)

  1. TagReadReplayService batching: Added BatchSize property and .Take() to prevent loading all records
  2. DatalogicBlobProcessor error handling: Added failed blobs to cache to prevent infinite retry

Files to Modify

  1. engines/iot/src/Acsis.Dynaplex.Engines.Iot.Abstractions/Services/DatalogicBlobProcessor.cs - Parse and use XML timestamp

Verification

After fix:

  1. Camera reads should use AcquisitionTriggerTimestamp from XML as EventTimestamp
  2. This should align with RFID tag read timestamps within the 5-second match window
  3. Matching should start working for camera reads and tag reads that occurred near the same time