【问题标题】:Orion CB doesn't update lazy attributes on IoT AgentOrion CB 不会更新 IoT 代理上的惰性属性
【发布时间】:2018-01-09 08:21:44
【问题描述】:

我正在尝试将 Orion CB 用作 IoT 代理的 Contex 提供程序,我在其中注册了仅具有惰性属性的设备。

在 IoT 代理上,我需要处理 updateContext 请求,因此我为这些请求做了一个处理程序,如下所示:

iotAgentLib.setDataUpdateHandler(updateContextHandler);

而在 updateContextHandler 函数中我只有一条指令:

console.log(attributes);

为了查看我要更新的所有值是否都已正确接收。

现在,如果我对设备表示的实体的属性之一进行更新:

curl -i -X POST \
-H "fiware-service:service1" \
-H "fiware-servicepath:/subservice1" \
-H "X-Auth-Token:wNRwDwqYlLoLD8U9sFkTAEE6PfYMbQ" \
-H "Content-Type:application/json" \
-d \
'{
    "contextElements": [
        {
            "id": "ncc_estimate",
            "attributes": [
                {
                    "name": "arrival",
                    "type": "string",
                    "value": "some_value"
                }
            ]
        }
    ],
    "updateAction": "UPDATE"
} ' \
'http://{orion_address}/v1/updateContext'

我在 IoT 代理输出控制台上看到的是:

time=2018-01-09T08:14:59.539Z | lvl=DEBUG | corr=2f4fdb0c-f515-11e7-86b2-0242ac110003 | trans=6ac5c35d-d7bf-419c-8f64-bc843b991d47 | op=IoTAgentNGSI.GenericMiddlewares | srv=service1 | subsrv=/subservice1 | msg=Body:

{
    "contextElements": [
        {
            "type": "nccestimate",
            "isPattern": "false",
            "id": "ncc_estimate",
            "attributes": [
                {
                    "name": "arrival",
                    "type": "string",
                    "value": ""
                }
            ]
        }
    ],
    "updateAction": "UPDATE"
}

你可以看到 value 字段是空的,我也可以从 UpdateHandler 函数中的 console.log() 输出中看到:

[ { name: 'arrival', type: 'string', value: '' } ]

似乎 Orion 在将其发送到 IoT 代理之前删除了该值。可能是什么问题呢?我做错了什么吗?

编辑:

这是对调用的响应:/v1/registry/contextEntities/ncc_estimate

{"contextRegistrationResponses":[
    {"contextRegistration":
        {"entities":[
            {
                "type":"nccestimate",
                "isPattern":"false",
                "id":"ncc_estimate"
            }
        ],
        "attributes":[
            {
                "name":"transport_type",
                "type":"string",
                "isDomain":"false"
            },
            {
                "name":"arrival",
                "type":"string",
                "isDomain":"false" 
           }
        ],
        "providingApplication":"http://192.168.199.151:4044"}
    }
]}

编辑2:

这是 Orion 在执行前面描述的 updateContext 操作时向 iot 代理发送的内容:

POST //updateContext HTTP/1.1
User-Agent: orion/1.10.0-next libcurl/7.19.7
Host: 192.168.199.151:4044
fiware-service: service1
Fiware-ServicePath: /subservice1
X-Auth-Token: M62UkJc7yKX5aQwaHrsODfIrV4Ou85
Accept: application/json
Content-length: 169
Content-type: application/json; charset=utf-8
Fiware-Correlator: 42561e9a-f615-11e7-8610-0242ac110003

{"contextElements":[{"type":"nccestimate","isPattern":"false","id":"ncc_estimate","attributes":[{"name":"arrival","type":"string","value":""}]}],"updateAction":"UPDATE"}

如您所见,该属性的“值”字段为空。 我正在使用 Orion 1.10.0 版和 iot 代理节点库 2.5.1 版。

【问题讨论】:

  • 惰性属性基于 IOTA 在配置时在 CB 创建的注册。这将是一个非常有用的信息,可以找出可能发生的事情。请检查与设备关联的 CB 注册(请参阅fiware-orion.readthedocs.io/en/master/user/walkthrough_apiv1/… 了解如何在 CB 发现现有注册)并编辑您的问题帖子以包含它。谢谢!
  • 我已经添加了您要求的内容,希望对您有所帮助。谢谢。
  • 注册好像没问题,它包含了lazy属性。让我们检查 Orion 实际发送的内容,以丢弃 IOTA 日志系统中的错误。为此,只需在配置设备后停止 IOTA,它们会在同一端口(如 nc 或 netcat)启动侦听器进程。然后,更新 CB 的属性并检查您在侦听器进程中获得的内容。请编辑包含该信息的问题帖子。
  • 此外,如果您在问题帖子中添加有关正在使用的 IOTA 和 Orion 版本的信息,那就太好了。
  • 我已经添加了您要求的内容。如您所见,没有任何值从 Orion 发送到 IoT 代理。

标签: fiware fiware-orion


【解决方案1】:

我使用与您相同的 CB 版本(即 1.10.0)进行了以下测试

首先,创建一个 IOTA 将创建的注册:

(curl -s -S localhost:1026/v1/registry/registerContext -H "fiware-service:service1" -H "fiware-servicepath:/subservice1" -H 'Content-Type: application/json' -d @- | python -mjson.tool) <<EOF
{
    "contextRegistrations": [
        {
            "entities": [
                {
                    "type": "nccestimate",
                    "isPattern": "false",
                    "id": "ncc_estimate"
                }
            ],
            "attributes": [
                {
                    "name": "transport_type",
                    "type": "string",
                    "isDomain": "false"
                },
                {
                    "name": "arrival",
                    "type": "string",
                    "isDomain": "false"
                }
            ],
            "providingApplication": "http://localhost:4044"
        }
    ],
    "duration": "P1M"
}
EOF

接下来,检查它是否与问题帖子中显示的注册完全相同(providingApplication 除外,它指向 localhost):

curl localhost:1026/v1/registry/contextEntities/ncc_estimate -s -S -H "fiware-service:service1" -H "fiware-servicepath:/subservice1" -H 'Accept: application/json' | python -mjson.tool

哪个响应是

{
    "contextRegistrationResponses": [
        {
            "contextRegistration": {
                "attributes": [
                    {
                        "isDomain": "false",
                        "name": "transport_type",
                        "type": "string"
                    },
                    {
                        "isDomain": "false",
                        "name": "arrival",
                        "type": "string"
                    }
                ],
                "entities": [
                    {
                        "id": "ncc_estimate",
                        "isPattern": "false",
                        "type": "nccestimate"
                    }
                ],
                "providingApplication": "http://localhost:4044"
            }
        }
    ]
}

接下来,在本地主机上的providingApplication 端口上运行nc 进程。

nc -l -p 4044

设置完成后,让我们先根据问题中的更新进行测试。

curl -s -S -X POST http://localhost:1026/v1/updateContext -H "fiware-service:service1" -H "fiware-servicepath:/subservice1" -H "Content-Type:application/json" -d @- <<EOF
{
    "contextElements": [
        {
            "id": "ncc_estimate",
            "attributes": [
                {
                    "name": "arrival",
                    "type": "string",
                    "value": "some_value"
                }
            ]
        }
    ],
    "updateAction": "UPDATE"
}
EOF

在这种情况下,Orion 无法识别注册并返回 Not Found 响应:

{
    "contextResponses": [{
        "contextElement": {
            "type": "",
            "isPattern": "false",
            "id": "ncc_estimate",
            "attributes": [{
                "name": "arrival",
                "type": "string",
                "value": ""
            }]
        },
        "statusCode": {
            "code": "404",
            "reasonPhrase": "No context element found",
            "details": "ncc_estimate"
        }
    }]
}

换句话说,Orion 不会转发响应。我不知道为什么在您的情况下被转发并在 IOTA 日志文件中留下痕迹。

下一个测试使用相同的请求,但为实体添加了type 字段。

curl -s -S -X POST http://localhost:1026/v1/updateContext -H "fiware-service:service1" -H "fiware-servicepath:/subservice1" -H "Content-Type:application/json" -d @- <<EOF
{
    "contextElements": [
        {
            "id": "ncc_estimate",
            "type": "nccestimate",
            "attributes": [
                {
                    "name": "arrival",
                    "type": "string",
                    "value": "some_value"
                }
            ]
        }
    ],
    "updateAction": "UPDATE"
}
EOF

在这种情况下,请求被转发,我在nc 终端中得到它。

POST //updateContext HTTP/1.1
User-Agent: orion/1.10.0 libcurl/7.38.0
Host: localhost:4044
fiware-service: service1
Fiware-ServicePath: /subservice1
Accept: application/json
Content-length: 179
Content-type: application/json; charset=utf-8
Fiware-Correlator: 42e75f8a-fa0d-11e7-93f1-000c29173617

{"contextElements":[{"type":"nccestimate","isPattern":"false","id":"ncc_estimate","attributes":[{"name":"arrival","type":"string","value":"some_value"}]}],"updateAction":"UPDATE"}

请注意响应中的some_value。在这种情况下,Orion 似乎正在正确处理请求。

编辑:根据用户的反馈,实体type 解决了这个问题。我们在the documentation regarding Context Providers 中强调它:

您应该在查询/更新中包含实体类型,以便 ContextBroker 能够转发到 Context Providers

【讨论】:

  • 请看一下我在回答帖子中描述的测试,它模仿了你的情况。但是,我得到的结果并不完全相同。我建议:1)在您的 CB 中运行相同的测试步骤“脚本”(首先清理数据库),2)尝试将实体类型添加到更新中(在 CB-IOTA 设置中)。
  • 谢谢,在更新请求中引入'type'字段解决了这个问题。
  • 感谢您的反馈!我们修改了文档以使其更清晰(见底部fiware-orion.readthedocs.io/en/master/user/context_providers/…)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-19
  • 2015-03-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多