发送到 ContextBroker 的命令未到达 IOT 代理

Command sent to ContextBroker doesn't reach IOT Agent

我在使用 MQTT 的 IoTAgent JSON 中的命令遇到了一些问题。我遵循这些说明:

POST ioat-agent:4041/iot/devices
{
  "devices": [
    {
      "device_id": "id_lamp1",
      "entity_name": "lamp1",
      "entity_type": "lamp",
      "attributes": [
        {
          "object_id": "l",
          "name": "luminosity",
          "type": "float"
        }
      ],
      "commands":[
        {
            "object_id": "u",
            "name": "ping",
            "type": "command"
        }
        ],
      "protocol": "IoTA-JSON",
      "transport": "MQTT"
    }
  ]
}

我尝试向 OCB 发送命令。类似的东西:

POST ocb:1026/v2/entities/lamp1/attrs?type=lamp
{
    "ping":{
        "type": "command",
        "value": "Ping Request"
    }
}

这似乎工作正常,因为我在日志中收到:

fiware-iot-agent | time=2019-05-16T09:42:00.436Z | lvl=DEBUG | corr=da768116-77be-11e9-8e17-0242ac140004 | trans=ed164f14-ffd8-404a-8da4-53b901d103b5 | op=IoTAgentNGSI.GenericMiddlewares | srv=myhome | subsrv=/environment | msg=Body:
fiware-iot-agent | {
fiware-iot-agent |     "entities": [
fiware-iot-agent |         {
fiware-iot-agent |             "type": "lamp",
fiware-iot-agent |             "isPattern": "false",
fiware-iot-agent |             "id": "lamp1"
fiware-iot-agent |         }
fiware-iot-agent |     ],
fiware-iot-agent |     "attributes": [
fiware-iot-agent |         "ping"
fiware-iot-agent |     ]
fiware-iot-agent | }
fiware-iot-agent |  | comp=IoTAgent
fiware-iot-agent | time=2019-05-16T09:42:00.457Z | lvl=DEBUG | corr=da768116-77be-11e9-8e17-0242ac140004 | trans=ed164f14-ffd8-404a-8da4-53b901d103b5 | op=IoTAgentNGSI.ContextServer | srv=myhome | subsrv=/environment | msg=Handling query from [iot-agent:4041] | comp=IoTAgent
fiware-iot-agent | time=2019-05-16T09:42:00.462Z | lvl=DEBUG | corr=da768116-77be-11e9-8e17-0242ac140004 | trans=ed164f14-ffd8-404a-8da4-53b901d103b5 | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=myhome | subsrv=/environment | msg=Looking for device with name [lamp1]. | comp=IoTAgent
fiware-iot-agent | time=2019-05-16T09:42:00.481Z | lvl=DEBUG | corr=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | trans=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | op=IoTAgentNGSI.MongoDBGroupRegister | srv=n/a | subsrv=n/a | msg=Looking for group params ["service","subservice","type"] with queryObj {"service":"myhome","subservice":"/environment","type":"lamp"} | comp=IoTAgent
fiware-iot-agent | time=2019-05-16T09:42:00.489Z | lvl=DEBUG | corr=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | trans=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | op=IoTAgentNGSI.MongoDBGroupRegister | srv=n/a | subsrv=n/a | msg=Device group for fields [["service","subservice","type"]] not found: [{"service":"myhome","subservice":"/environment","type":"lamp"}] | comp=IoTAgent
fiware-iot-agent | time=2019-05-16T09:42:00.491Z | lvl=ERROR | corr=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | trans=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | op=IoTAgentNGSI.Alarms | srv=n/a | subsrv=n/a | msg=Raising [MONGO-ALARM]: {"name":"DEVICE_GROUP_NOT_FOUND","message":"Couldn\t find device group","code":404} | comp=IoTAgent
fiware-iot-agent | time=2019-05-16T09:42:00.495Z | lvl=DEBUG | corr=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | trans=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | op=IoTAgentNGSI.ContextServer | srv=n/a | subsrv=n/a | msg=Handling received set of attributes: ["ping"] | comp=IoTAgent
fiware-iot-agent | time=2019-05-16T09:42:00.496Z | lvl=DEBUG | corr=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | trans=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | op=IoTAgentNGSI.MongoDBDeviceRegister | srv=n/a | subsrv=n/a | msg=Looking for device with name [lamp1]. | comp=IoTAgent
fiware-iot-agent | time=2019-05-16T09:42:00.506Z | lvl=ERROR | corr=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | trans=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | op=IoTAgentNGSI.Alarms | srv=n/a | subsrv=n/a | msg=Releasing [MONGO-ALARM] | comp=IoTAgent
fiware-iot-agent | time=2019-05-16T09:42:00.509Z | lvl=DEBUG | corr=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | trans=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | op=IoTAgentNGSI.ContextServer | srv=n/a | subsrv=n/a | msg=Query from [iot-agent:4041] handled successfully. | comp=IoTAgent
fiware-iot-agent | time=2019-05-16T09:42:00.511Z | lvl=DEBUG | corr=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | trans=3273f192-1cdc-42dc-80b1-9e0cab5a8a2b | op=IoTAgentNGSI.ContextServer | srv=n/a | subsrv=n/a | msg=Generated query response: {"contextResponses":[{"contextElement":{"type":"lamp","isPattern":false,"id":"lamp1","attributes":[{"name":"ping","type":"command","value":""}]},"statusCode":{"code":200,"reasonPhrase":"OK"}}]} | comp=IoTAgent

但我没有收到主题 /1234/id_lamp1/cmd 中的任何消息,并且我没有在 te OCB 实体的 ring_status 属性中看到 PENDING。虽然当我模拟 lamp1 设备并在 /1234/id_lamp1/cmdexe 中发布消息时,ring_status 和 ring_info 分别更改为 OK 和 22。

问题是由于使用了 POST 动词(在 POST /v2/entities/lamp1/attrs?type=lamp 中)来发送命令。 POST 具有创建语义,因此它将向实体添加 ping 属性,而不是将其转发给 IOTA。因此,命令永远不会到达 IOTA,因此 IOTA 永远不会在 MQTT 代理中发布。这在 this section of the documentation 的 "Important Note" 中有更详细的解释。

但是,如果您使用 PATCH 而不是 POST(即 PATCH /v2/entities/lamp1/attrs?type=lamp),则会进行转发,因此 IOTA 会收到命令并且 IOTA 将在 /1234/[ 中发布 {"ping":"Ping Request"} =26=] MQTT 代理中的主题。

如果您已经 POST /v2/entities/lamp1/attrs?type=lamp 那么首先您必须解决在 Orion Context Broker API 上使用 DELETE /v2/entities/lamp1/attrs/ping 删除属性的情况。否则,当您执行 PATCH 时,您使用 POST 创建的本地 ping 属性将优先于 IOTA 的 ping 注册属性,并且不会进行转发。