Uploaded image for project: 'Help-Desk'
  1. Help-Desk
  2. HELP-23004

FIWARE.Question.Tech.IoTAgent JSON MQTT and timestamps attributes.

    Details

      Description

      Created question in FIWARE Q/A platform on 21-02-2024 at 17:02
      Please, ANSWER this question AT https://stackoverflow.com/questions/78035536/iotagent-json-mqtt-and-timestamps-attributes

      Question:
      IoTAgent JSON MQTT and timestamps attributes

      Description:
      I am trying to integrate MQTT devices with the FIWARE JSON IoT agent and I have some doubts about it.
      The goal I want to achieve is to try to provision devices through DeviceMeasurement entities to follow the model proposed in SmartDataModels. This model proposes to store the timestamp of the measurement in the "dateObserved" attribute. In contrast, the NGSI-LD standard suggests storing the timestamp as metadata "observedAt" in the attribute itself (in this case, attribute "numValue"). Since I present historical repository implementations using dateObserved, I want to keep this attribute and also consider adding the same timestamp as metadata (observedAt) of the "numValue" attribute to make it compatible with Temporal API implementations such as Mintaka (which makes use of the "observedAt" metadata).
      In short, I want to store the timestamp both in a "dateObserved" attribute and as "observedAt" metadata, so I want the entity to be displayed in this way:
      {
      "id": "urn:ngsi-ld:DeviceMeasurement:device1-temperature",
      "type": "DeviceMeasurement",
      "numValue":

      { "type": "Property", "value": 232.3, "unitCode": "CEL", "observedAt" : "2024-06-21T11:15:00.000Z" }

      ,
      "dateObserved": {
      "type": "Property",
      "value":

      { "@type": "DateTime", "@value": "2024-06-21T11:15:00.000Z" }

      },
      "refDevice":

      { "type": "Relationship", "object": "urn:ngsi-ld:Device:device1" }

      ,
      "controlledProperty":

      { "type": "Property", "value": "temperature" }

      }

      To try to do this, I provisioned the device like this:
      {
      "device_id": "device1-temperature",
      "apikey": "apikey_test",
      "service": <service>,
      "service_path": "/",
      "entity_name": "urn:ngsi-ld:DeviceMeasurement:device1-temperature",
      "entity_type": "DeviceMeasurement",
      "timestamp": true,
      "transport": "MQTT",
      "attributes": [

      { "object_id": "dateObserved", "name": "dateObserved", "type": "DateTime" }

      ,
      {
      "object_id": "numValue",
      "name": "numValue",
      "type": "Property",
      "metadata": {
      "unitCode":

      { "type": "Text", "value": "CEL" }

      }
      }
      ],
      "lazy": [],
      "commands": [],
      "static_attributes": [

      { "name": "refDevice", "type": "Relationship", "value": "urn:ngsi-ld:Device:device1" }

      ,

      { "name": "controlledProperty", "type": "Property", "value": "temperature" }

      ],
      "protocol": "MQTT_JSON"
      }

      and sending the following MQTT message:

      {"numValue":232.3,"dateObserved":"2024-06-21T11:30:00.000Z", "TimeInstant" : "2024-06-21T11:30:00.000Z" }

      the entity shows the following:
      {
      "id": "urn:ngsi-ld:DeviceMeasurement:device1-temperature",
      "type": "DeviceMeasurement",
      "numValue":

      { "type": "Property", "value": 232.3, "unitCode": "CEL", "observedAt": "2024-06-21T11:30:00.000Z" }

      ,
      "dateObserved": {
      "type": "Property",
      "value":

      { "@type": "DateTime", "@value": "2024-06-21T11:30:00.000Z" }

      ,
      "observedAt": "2024-06-21T11:30:00.000Z"
      },
      "refDevice":

      { "type": "Relationship", "object": "urn:ngsi-ld:Device:device1", "observedAt": "2024-06-21T11:30:00.000Z" }

      ,
      "controlledProperty":

      { "type": "Property", "value": "temperature", "observedAt": "2024-06-21T11:30:00.000Z" }

      }

      According to IoTAgent documentation, I have to include the timestamp as "TimeInstant" in the payload of the MQTT message, but this timestamp is added as metadata to all attributes (dynamic and static), when I only want to add it to numValue.
      Is there any way to ensure that the "observedAt" metadata is added only to the desired attribute (dynamic) as is the case of "numValue"?
      Thanks

        Activity

        Hide
        newbacklogmanager Backlog Manager added a comment -

        2025-02-04 17:53|CREATED monitor | # answers= 1, accepted answer= True

        Show
        newbacklogmanager Backlog Manager added a comment - 2025-02-04 17:53|CREATED monitor | # answers= 1, accepted answer= True
        Hide
        newbacklogmanager Backlog Manager added a comment -

        2025-02-05 01:01|UPDATED status: transition Answer| # answers= 1, accepted answer= True

        Show
        newbacklogmanager Backlog Manager added a comment - 2025-02-05 01:01|UPDATED status: transition Answer| # answers= 1, accepted answer= True
        Hide
        newbacklogmanager Backlog Manager added a comment -

        2025-02-06 01:01|UPDATED status: transition Finish| # answers= 1, accepted answer= True

        Show
        newbacklogmanager Backlog Manager added a comment - 2025-02-06 01:01|UPDATED status: transition Finish| # answers= 1, accepted answer= True

          People

          • Assignee:
            Unassigned
            Reporter:
            newbacklogmanager Backlog Manager
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: