首页 > 解决方案 > IoT-Agent 检查不在 iot 有效负载中的默认属性

问题描述

我有一个测试环境,其中我为 JSON IoT 代理配置了一个服务组,其中包含一个旧表达式:

{
            "_id": "60acc2d549e4721ae5087356",
            "__v": 0,
            "iotagent": "http://10.0.0.2:4062",
            "apikey": "apikeyTest2",
            "entity_type": "WasteContainer",
            "service_path": "/subservice",
            "service": "service",
            "resource": "/iot/json",
            "description": "IoTAgent JSON - Node.js",
            "protocol": "IoTA-JSON",
            "internal_attributes": [],
            "attributes": [
                {
                    "name": "temperature",
                    "object_id": "t",
                    "type": "Number"
                },
                {
                    "name": "fillingLevel",
                    "expression": "${@level/100}",
                    "type": "Number"
                }
            ],
            "lazy": [],
            "static_attributes": [],
            "commands": []
        }

除此之外,我手动注册了一个带有“jexl”作为表达式语言的设备:

curl --location --request POST 'https://host/iot/devices' \
--header 'Fiware-Service: service' \
--header 'Fiware-ServicePath: /subservice' \
--header 'X-Auth-Token: gAAAAABgrQm..._R8r98aeNWQ' \
--header 'Content-Type: application/json' \
--data-raw '{
  "devices": [
    {
      "device_id": "deviceJSON1",
      "entity_name": "device:entity01",
      "entity_type": "device",
      "expressionLanguage": "jexl",
      "attributes": [
        { 
          "object_id": "b",
          "name": "position", 
          "type": "Number",
          "expression": "(a+b)"
        }
      ],
      "protocol": "IoTA-JSON",
      "transport": "HTTP"
    }
  ]
}
'

然后我使用前一个服务组的 apikey 从设备发送数据,但不使用那里配置的任何属性:

curl --location --request POST 'http://host/iot/json?k=apikeyTest2&i=deviceJSON1&getCmd=0' \
--header 'Content-Type: application/json' \
--data-raw '{
    "a": 4,
    "b": 5
}'

响应是 400 错误请求:

{
    "name": "INVALID_EXPRESSION",
    "message": "Invalid expression in evaluation [${@level/100}]"
}

这是预期的结果还是代理应该尝试使用“jexl”来转换有效负载,因为物level联网数据中没有属性?

为了解决这个问题,我可以创建另一个具有不同 apikey 且没有默认属性的服务组,但只是想知道结果是否符合预期。

标签: iotfiware

解决方案


推荐阅读