Fiware JSON IoT代理是否期望从设备获得答案?

问题描述 投票:0回答:1

我在当地运行Fiware IoT Agent example。计划是将它连接到某种设备并进行演示。我正在使用request bin来检查IoT代理发送的请求。

./services start启动环境后,我调用这个shell脚本在代理中注册一个铃声设备,然后触发“ring”命令。

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响应,我可以在请求bin中看到请求。

$ ./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 compose文件中的图像。

  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。这是否意味着物联网代理期待来自“设备”的更具体的响应?

请求可以在请求bin中看到,因此它可以工作到那么远。但为什么代理人认为存在问题?它是否期望某种特定的响应格式?

我已经尝试将设备注册步骤中的“协议”转换为“PDI-IoTA-JSON”。这没有用。

fiware
1个回答
0
投票

问题是IoT代理假定设备将使用JSON进行响应。 Requestbin的默认答案是字符串“ok”。这导致代理崩溃。

如果设备返回{},请求成功,如果它返回命令结果的某些信息,则更成功。例如。

{
  "ring": "successfully rung"
}
© www.soinside.com 2019 - 2024. All rights reserved.