Orion CB不会更新IoT Agent上的惰性属性 [英] Orion CB doesn't update lazy attributes on IoT Agent
问题描述
我正在尝试使用Orion CB作为IoT代理的Contex Provider,在该IoT代理中,我仅注册了具有惰性属性的设备.
I'm trying to use Orion CB as Contex Provider for an IoT Agent in which I have registred a device with lazy attributes only.
在IoT代理上,我需要处理updateContext请求,因此我为这些请求做了一个处理程序,如下所示:
On the IoT Agent I need to handle updateContext requests so I did a handler for these requests like this:
iotAgentLib.setDataUpdateHandler(updateContextHandler);
在updateContextHandler函数中,我只有一条指令:
And in the updateContextHandler function I have only one instruction:
console.log(attributes);
为了查看是否正确接收了我要更新的所有值.
In order to see if all the values I want to update have been received correctly.
现在,如果我对设备代表的实体的属性之一进行更新:
Now if I do an update on one of the attributes of the entity represented by the device:
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 Agent输出控制台上看到的是:
What I see on the IoT Agent output console is:
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()输出中看到的一样:
Where as you can see the value field is empty, as I can also see from the console.log() output in the UpdateHandler function that is:
[ { name: 'arrival', type: 'string', value: '' } ]
似乎Orion在将其发送到IoT代理之前正在删除该值.可能是什么问题呢?我在做某件事上错了吗?
It seems that Orion is deleting the value before sending it to the IoT Agent. What could be the problem? Am I wrong doing something?
以下是对/v1/registry/contextEntities/ncc_estimate的调用的响应
Here is the response for the call to: /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"}
}
]}
edit2:
这是Orion执行前面所述的updateContext操作时发送给iot代理的内容:
This is what Orion is sending to the iot agent when performing the updateContext operation described before:
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.
As you can see the "value" field for the attribute is empty. I'm using Orion version 1.10.0 and iot agent node lib version 2.5.1.
推荐答案
我已经使用与您的版本相同的CB(即1.10.0)进行了以下测试
I have done the following test using CB same version as yours (i.e. 1.10.0)
首先,创建一个注册,作为IOTA会创建的注册:
First, create a registration as the one that IOTA would create:
(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
除外,它指向本地主机):
Next, check that it is exactly the same registration shown in the question post (except by the providingApplication
, that points to 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
进程.
Next, run nc
process at localhost on providingApplication
port.
nc -l -p 4044
设置完成后,让我们首先根据问题中的内容进行更新测试.
Once the setup is done, let's test first with an update based on the one in the question.
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无法识别注册并返回未找到"响应:
In this case, Orion doesn't recognized the registration and returns a Not Found response:
{
"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日志文件中留下痕迹.
In other words, Orion is not forwarding the response. I don't know why in your case is forwarded and leaves a trace in IOTA log file.
下一个测试使用相同的请求,但为实体添加了 type
字段.
Next test uses the same request but adding a type
field for the entity.
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
终端中收到了该请求.
In this case, the request is forwarded and I get this in the nc
terminal.
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似乎可以正确处理请求.
Note the some_value
in the response. Orion seems to be progressing correctly the request in this case.
编辑:根据用户的反馈,实体 type
解决了该问题.我们在与上下文提供程序有关的文档中突出显示:
according to user's feedback, entity type
solved the problem. We are highlighting it in the documentation regarding Context Providers:
您应该在查询/更新中包括实体类型,以便ContextBroker能够转发到Context Providers
You should include entity type in the query/update in order for the ContextBroker to be able to forward to Context Providers
这篇关于Orion CB不会更新IoT Agent上的惰性属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!