From 94d9922f15f71448880dcaa6cb5f3c3b2fb813ab Mon Sep 17 00:00:00 2001 From: Andreas Motl Date: Sat, 20 Nov 2021 19:46:25 +0100 Subject: [PATCH] Add `timestamp` field into outbound telemetry message --- src/lib/terkin/telemetry/core.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/terkin/telemetry/core.py b/src/lib/terkin/telemetry/core.py index 517cf8c..985eedc 100644 --- a/src/lib/terkin/telemetry/core.py +++ b/src/lib/terkin/telemetry/core.py @@ -324,6 +324,14 @@ def transmit(self, dataframe: DataFrame, uri=None, serialize=True): # Resolve handler by URI. handler = self.get_handler(real_uri) + # Add timestamp to outbound telemetry message. + # TODO: Using the timestamp of the first reading is a bit vague. + # How can it be improved? + try: + dataframe.data_out["timestamp"] = dataframe.readings[0].timestamp + except IndexError: + pass + # Prepare dataframe for egress. dataframe.payload_out = dataframe.data_out if serialize: