Details
-
Type:
Monitor
-
Status: Closed
-
Priority:
Major
-
Resolution: Done
-
Affects Version/s: None
-
Fix Version/s: None
-
Component/s: FIWARE-TECH-HELP
-
Labels:
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":
,
"dateObserved": {
"type": "Property",
"value":
},
"refDevice":
,
"controlledProperty":
}
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": "numValue",
"name": "numValue",
"type": "Property",
"metadata": {
"unitCode":
}
}
],
"lazy": [],
"commands": [],
"static_attributes": [
,
{ "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":
,
"dateObserved": {
"type": "Property",
"value":
,
"observedAt": "2024-06-21T11:30:00.000Z"
},
"refDevice":
,
"controlledProperty":
}
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
2025-02-04 17:53|CREATED monitor | # answers= 1, accepted answer= True