In general, the Edge is the source of truth for tag timestamps although there are several events that will cause the timestamps to differ across the system:
In a BIRTH message
- The BIRTH message for each Edge Node and Device will set the timestamp associated with each tag to the current time of the publishing client server's OS.
- This means that the timestamp at the Edge will show the last known timestamp and the receiving application will display the timestamp included in the BIRTH message.
OPC Tag Disabled
- When an OPC tag is disabled, the timestamp at Edge will reflect the time the tag was disabled.
- The associated DDATA message will reflect the timestamp of the disabled tag change event.
OPC Tag Enabled
- When an OPC tag is enabled, the timestamp at Edge will reflect the last known change timestamp from the PLC.
- The associated DDATA message will reflect the timestamp of the enabled tag change event.
OPC Restart Tag
- When an OPC tag is restarted, the timestamp at Edge will reflect the last known change timestamp from the PLC.
- The associated DDATA message will reflect the timestamp of the tag restart event.
Common scenarios where timestamps can be different across the MQTT system
Let's assume an Edge Node has a single tag named Tag1
MQTT Transmission Store and Forward Not Enabled
- Transmission connects and publishes its BIRTH
- The timestamp for Tag1 set at the Edge to 'now' per the Edge's system clock.
- Tag change events occur naturally at the Edge
- During this time the timestamp is always set using the tag change event time at the Edge. This results in Tag1's timestamp at Engine matching that of the Edge.
- Transmission loses connection.
- At this point, Engine 'stales' the tag by setting the quality to BAD_STALE and sets the timestamp of Tag1 to 'now' per the Central Gateway's system clock.
- The tag may or may not be changing at the Edge - Engine won't know in real time this is happening so it sets the quality of Tag1 to BAD_STALE.
- Transmission reconnects and publishes its BIRTH
- The timestamp for Tag1 set at the Edge to 'now' per the Edge's system clock.
- Assuming the quality of Tag1 at the Edge is GOOD - it will be set to GOOD at Engine.
- If the tag value had never changed at the Edge, then you would see three events with the same value, three different timestamps, and the quality go from GOOD -> BAD_STALE -> GOOD.
MQTT Transmission Store and Forward Enabled with Flush history in-order (synchronously)
- Transmission connects and publishes its BIRTH
- The timestamp for Tag1 set at the Edge to 'now' per the Edge's system clock.
- Tag change events occur naturally at the Edge
- During this time the timestamp is always set using the tag change event time at the Edge. This results in Tag1's timestamp at Engine matching that of the Edge.
- Transmission loses connection
- Transmission caches a BIRTH to the history store with the timestamp for Tag1 set to 'now' per the Edge's system clock.
- All changes to Tag1 at the Edge are stored to the configured History Store.
- At this point, Engine 'stales' the tag by setting the quality to BAD_STALE and sets the timestamp of Tag1 to 'now' per the Central Gateway's system clock.
- The tag may or may not be changing at the Edge - Engine won't know in real time this is happening so it sets the quality of Tag1 to BAD_STALE.
- Transmission reconnects and publishes the cached history store BIRTH
- The timestamp for Tag1 set at the Edge to 'now' per the Edge's system clock.
- The history store is flushed before any live data is published. This means that any changes to Tag1 will be stored to the history store until the flush is complete.
- Assuming the quality of Tag1 at the Edge is GOOD - it will be set to GOOD at Engine.
- If the tag value had never changed at the Edge, then you would see three events with the same value, three different timestamps, and the quality go from GOOD -> BAD_STALE -> GOOD.
MQTT Transmission Store and Forward Enabled with Flush history (asynchronously)
- Transmission connects and publishes its BIRTH
- The timestamp for Tag1 set at the Edge to 'now' per the Edge's system clock.
- Tag change events occur naturally at the Edge
- During this time the timestamp is always set using the tag change event time at the Edge. This results in Tag1's timestamp at Engine matching that of the Edge.
- Transmission loses connection
- Transmission caches a BIRTH to the history store with the timestamp for Tag1 set to 'now' per the Edge's system clock.
- All changes to Tag1 at the Edge are stored to the configured History Store.
- At this point, Engine 'stales' the tag by setting the quality to BAD_STALE and sets the timestamp of Tag1 to 'now' per the Central Gateway's system clock.
- The tag may or may not be changing at the Edge - Engine won't know in real time this is happening so it sets the quality of Tag1 to BAD_STALE.
- Transmission reconnects and publishes the cached history store BIRTH
- The timestamp for Tag1 set at the Edge to 'now' per the Edge's system clock.
- The history store will be flushed whilst live data is published. This means that any changes to Tag1 will be interleaved with the historic data publishes.
- Assuming the quality of Tag1 at the Edge is GOOD - it will be set to GOOD at Engine.
- If the tag value had never changed at the Edge, then you would see three events with the same value, three different timestamps, and the quality go from GOOD -> BAD_STALE -> GOOD.