Fiware JSON IoT Agent 是否需要设备的响应?
Does the Fiware JSON IoT Agent expect an answer from devices?
我 运行 Fiware IoT Agent example locally. The plan is to hook this up to some sort of Device and make a demo. I'm using request bin 负责检查从 IoT 代理发送的请求。
在使用 ./services start
启动环境后,我调用这个 shell 脚本在代理中注册一个响铃设备,然后触发“响铃”命令。
curl -iX POST \
'http://localhost:4041/iot/devices' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"devices": [
{
"device_id": "bell001",
"entity_name": "urn:ngsi-ld:Bell:001",
"entity_type": "Bell",
"protocol": "PDI-IoTA-UltraLight",
"transport": "HTTP",
"endpoint": "https://requestbin.fullcontact.com/zhygotzh/iot/bell001",
"commands": [
{ "name": "ring", "type": "command" }
],
"static_attributes": []
}
]
}
'
curl -iX POST \
'http://localhost:4041/v1/updateContext' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"contextElements": [
{
"type": "Bell",
"isPattern": "false",
"id": "urn:ngsi-ld:Bell:001",
"attributes": [
{ "name": "ring", "type": "command", "value": "" }
],
"static_attributes": []
}
],
"updateAction": "UPDATE"
}'
效果很好,我收到了 200 响应,我可以在请求箱中看到请求。
$ ./setup-ul.sh
HTTP/1.1 201 Created
X-Powered-By: Express
Fiware-Correlator: 8298b65a-8550-4b6e-8a4d-21bc32abdf8a
Content-Type: application/json; charset=utf-8
Content-Length: 2
ETag: W/"2-vyGp6PvFo4RvsFtPoIWeCReyIC8"
Date: Fri, 29 Mar 2019 11:34:05 GMT
Connection: keep-alive
{}HTTP/1.1 200 OK
X-Powered-By: Express
Fiware-Correlator: c79a1146-05d8-4eb1-8e1c-bf19661cb403
Content-Type: application/json; charset=utf-8
Content-Length: 208
ETag: W/"d0-6+Ce6hwRVmP90ZI667iON6zHtdA"
Date: Fri, 29 Mar 2019 11:34:07 GMT
Connection: keep-alive
{"contextResponses":[{"contextElement":{"attributes":[{"name":"ring","type":"command","value":""}],"id":"urn:ngsi-ld:Bell:001","isPattern":false,"type":"Bell"},"statusCode":{"code":200,"reasonPhrase":"OK"}}]}
但是,请求是 Ultra Light 格式的。我更喜欢 JSON 格式。所以我想我只是替换 docker 撰写文件中的图像。
iot-agent:
image: fiware/iotagent-ul:1.8.0
hostname: iot-agent
更改为
iot-agent:
image: fiware/iotagent-json
hostname: iot-agent
在 docker-compose.yml
.
现在,当我对更新后的 docker-compose 文件尝试同样的操作时,我得到以下结果:
$ ./setup.sh
HTTP/1.1 201 Created
X-Powered-By: Express
Fiware-Correlator: 69d6a6ad-a44a-4e57-87dd-4e512d499fee
Content-Type: application/json; charset=utf-8
Content-Length: 2
ETag: W/"2-vyGp6PvFo4RvsFtPoIWeCReyIC8"
Date: Fri, 29 Mar 2019 11:44:36 GMT
Connection: keep-alive
{}HTTP/1.1 400 Bad Request
X-Powered-By: Express
Fiware-Correlator: 6c9a28b5-0505-456c-bcdb-841df2bc6f62
Content-Type: application/json; charset=utf-8
Content-Length: 388
ETag: W/"184-RqfzTJc6iD9nXX3kAbxZqwruJC0"
Date: Fri, 29 Mar 2019 11:44:37 GMT
Connection: keep-alive
{"contextResponses":[{"contextElement":{"contextElements":[{"type":"Bell","isPattern":"false","id":"urn:ngsi-ld:Bell:001","attributes":[{"name":"ring","type":"command","value":""}],"static_attributes":[]}],"updateAction":"UPDATE"},"statusCode":{"code":400,"reasonPhrase":"HTTP_COMMAND_RESPONSE_ERROR","details":"There was an error in the response of a device to a command [400 ]:null"}}]}
这似乎是相关部分:There was an error in the response of a device to a command [400 ]:null
。这是否意味着 IoT 代理期望来自“设备”的一些更具体的响应?
可以在请求箱中看到该请求,所以到目前为止它已经成功了。但是为什么代理人认为有问题呢?它是否需要某种特定的响应格式?
我也试过将设备注册步骤中的“协议”链接到“PDI-IoTA-JSON”。那没有帮助。
问题是 IoT 代理假设设备将响应 JSON。 Requestbin 的默认答案是字符串 "ok"。这导致代理崩溃。
如果设备returns {}
请求成功,如果它returns关于命令结果的一些信息,则请求成功。例如
{
"ring": "successfully rung"
}
我 运行 Fiware IoT Agent example locally. The plan is to hook this up to some sort of Device and make a demo. I'm using request bin 负责检查从 IoT 代理发送的请求。
在使用 ./services start
启动环境后,我调用这个 shell 脚本在代理中注册一个响铃设备,然后触发“响铃”命令。
curl -iX POST \
'http://localhost:4041/iot/devices' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"devices": [
{
"device_id": "bell001",
"entity_name": "urn:ngsi-ld:Bell:001",
"entity_type": "Bell",
"protocol": "PDI-IoTA-UltraLight",
"transport": "HTTP",
"endpoint": "https://requestbin.fullcontact.com/zhygotzh/iot/bell001",
"commands": [
{ "name": "ring", "type": "command" }
],
"static_attributes": []
}
]
}
'
curl -iX POST \
'http://localhost:4041/v1/updateContext' \
-H 'Content-Type: application/json' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-d '{
"contextElements": [
{
"type": "Bell",
"isPattern": "false",
"id": "urn:ngsi-ld:Bell:001",
"attributes": [
{ "name": "ring", "type": "command", "value": "" }
],
"static_attributes": []
}
],
"updateAction": "UPDATE"
}'
效果很好,我收到了 200 响应,我可以在请求箱中看到请求。
$ ./setup-ul.sh
HTTP/1.1 201 Created
X-Powered-By: Express
Fiware-Correlator: 8298b65a-8550-4b6e-8a4d-21bc32abdf8a
Content-Type: application/json; charset=utf-8
Content-Length: 2
ETag: W/"2-vyGp6PvFo4RvsFtPoIWeCReyIC8"
Date: Fri, 29 Mar 2019 11:34:05 GMT
Connection: keep-alive
{}HTTP/1.1 200 OK
X-Powered-By: Express
Fiware-Correlator: c79a1146-05d8-4eb1-8e1c-bf19661cb403
Content-Type: application/json; charset=utf-8
Content-Length: 208
ETag: W/"d0-6+Ce6hwRVmP90ZI667iON6zHtdA"
Date: Fri, 29 Mar 2019 11:34:07 GMT
Connection: keep-alive
{"contextResponses":[{"contextElement":{"attributes":[{"name":"ring","type":"command","value":""}],"id":"urn:ngsi-ld:Bell:001","isPattern":false,"type":"Bell"},"statusCode":{"code":200,"reasonPhrase":"OK"}}]}
但是,请求是 Ultra Light 格式的。我更喜欢 JSON 格式。所以我想我只是替换 docker 撰写文件中的图像。
iot-agent:
image: fiware/iotagent-ul:1.8.0
hostname: iot-agent
更改为
iot-agent:
image: fiware/iotagent-json
hostname: iot-agent
在 docker-compose.yml
.
现在,当我对更新后的 docker-compose 文件尝试同样的操作时,我得到以下结果:
$ ./setup.sh
HTTP/1.1 201 Created
X-Powered-By: Express
Fiware-Correlator: 69d6a6ad-a44a-4e57-87dd-4e512d499fee
Content-Type: application/json; charset=utf-8
Content-Length: 2
ETag: W/"2-vyGp6PvFo4RvsFtPoIWeCReyIC8"
Date: Fri, 29 Mar 2019 11:44:36 GMT
Connection: keep-alive
{}HTTP/1.1 400 Bad Request
X-Powered-By: Express
Fiware-Correlator: 6c9a28b5-0505-456c-bcdb-841df2bc6f62
Content-Type: application/json; charset=utf-8
Content-Length: 388
ETag: W/"184-RqfzTJc6iD9nXX3kAbxZqwruJC0"
Date: Fri, 29 Mar 2019 11:44:37 GMT
Connection: keep-alive
{"contextResponses":[{"contextElement":{"contextElements":[{"type":"Bell","isPattern":"false","id":"urn:ngsi-ld:Bell:001","attributes":[{"name":"ring","type":"command","value":""}],"static_attributes":[]}],"updateAction":"UPDATE"},"statusCode":{"code":400,"reasonPhrase":"HTTP_COMMAND_RESPONSE_ERROR","details":"There was an error in the response of a device to a command [400 ]:null"}}]}
这似乎是相关部分:There was an error in the response of a device to a command [400 ]:null
。这是否意味着 IoT 代理期望来自“设备”的一些更具体的响应?
可以在请求箱中看到该请求,所以到目前为止它已经成功了。但是为什么代理人认为有问题呢?它是否需要某种特定的响应格式?
我也试过将设备注册步骤中的“协议”链接到“PDI-IoTA-JSON”。那没有帮助。
问题是 IoT 代理假设设备将响应 JSON。 Requestbin 的默认答案是字符串 "ok"。这导致代理崩溃。
如果设备returns {}
请求成功,如果它returns关于命令结果的一些信息,则请求成功。例如
{
"ring": "successfully rung"
}