我正在尝试使用Orion CB作为物联网代理的Contex提供商,我在其中注册了仅具有延迟属性的设备 .
在物联网代理上我需要处理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 Agent输出控制台上看到的是:
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"
}
您可以在哪里看到值字段为空,我也可以从UpdateHandler函数中的console.log()输出中看到:
[ { name: 'arrival', type: 'string', value: '' } ]
似乎Orion在将值发送给IoT Agent之前删除了该值 . 可能是什么问题呢?我做错了什么?
编辑:
以下是对/ 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代理的内容:
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代理节点lib版本2.5.1 .
1 回答
我使用与您相同的CB版本进行了以下测试(即1.10.0)
首先,创建IOTA创建的注册:
接下来,检查它与问题帖子中显示的注册完全相同(除了
providingApplication
,指向localhost):反应是什么
接下来,在
providingApplication
port上的localhost上运行nc
进程 .设置完成后,首先让我们根据问题中的更新进行测试 .
在这种情况下,Orion不会识别注册并返回Not Found响应:
换句话说,Orion没有转发响应 . 我不知道为什么在你的情况下转发并在IOTA日志文件中留下痕迹 .
下一个测试使用相同的请求,但为实体添加
type
字段 .在这种情况下,请求被转发,我在
nc
终端中得到了这个 .请注意响应中的
some_value
. 在这种情况下,Orion似乎正在正确地进行请求 .EDIT: 根据用户的反馈,实体
type
解决了这个问题 . 我们在the documentation regarding Context Providers中突出显示它: