IoTAgent JSON MQTT 和时间戳属性

问题描述 投票:0回答:1

我正在尝试将 MQTT 设备与 FIWARE JSON IoT 代理集成,但我对此有一些疑问。

我想要实现的目标是尝试通过 DeviceMeasurement 实体配置设备以遵循 SmartDataModels 中提出的模型。该模型建议将测量的时间戳存储在“dateObserved”属性中。相反,NGSI-LD 标准建议将时间戳作为元数据“observedAt”存储在属性本身中(在本例中为属性“numValue”)。由于我使用 dateObserved 呈现历史存储库实现,因此我想保留此属性,并考虑添加与“numValue”属性的元数据 (observedAt) 相同的时间戳,以使其与 Temporal API 实现兼容,例如 Mintaka(它利用“observedAt”元数据)。

简而言之,我想将时间戳存储在“dateObserved”属性中并作为“observedAt”元数据,因此我希望实体以这种方式显示:

 {
    "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"
    }
}

为了尝试做到这一点,我像这样配置了设备:

{
            "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"
        }

并发送以下 MQTT 消息:

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

实体显示以下内容:

{
    "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"
    }
}

根据 IoTAgent 文档,我必须将时间戳作为“TimeInstant”包含在 MQTT 消息的有效负载中,但当我只想将其添加到 numValue 时,此时间戳会作为元数据添加到所有属性(动态和静态)。

有什么方法可以确保“observedAt”元数据仅添加到所需的属性(动态),就像“numValue”的情况一样?

谢谢

iot fiware fiware-orion
1个回答
0
投票

我可以回答有关 IotAgent NGSIv2 Northbound 绑定的问题。我几乎可以肯定它的行为与 NGSI-LD 绑定相同。

恐怕当前的行为就像您所说的那样:如果存在

timestamp==true
TimeInstant
度量,则 TimeInstant 度量的值将用作 TimeInstant 属性的值,并作为元数据添加到 每个传播的属性,在本例中是活动属性和静态属性。就其进展而言,元数据应该有意义。

您可以使用

explicitAttrs
和/或
skipValue
功能来过滤将传播的属性,但我认为在这种情况下不是您所需要的。

作为替代方案,我们可以通过使用新的 NGSI 有效负载支持来发送元数据作为度量的一部分。通过这种方式,您有权按照您的预期在 NGSI 负载(v2 或 Ld)中发送元数据,并设置

timestamp==false
。我认为这将使最终属性可以访问元数据。

© www.soinside.com 2019 - 2024. All rights reserved.