首页 > 解决方案 > 发送到 ContextBroker 的命令未到达 IOT 代理

问题描述

我在使用 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。

标签: fiwarefiware-orion

解决方案


问题是由于使用 POST 动词 (in POST /v2/entities/lamp1/attrs?type=lamp) 来发送命令。POST 具有创建语义,因此它将ping属性添加到实体而不是将其转发给 IOTA。因此,命令永远不会到达 IOTA,因此 IOTA 永远不会在 MQTT 代理中发布。这在文档本节的“重要说明”中有更详细的解释。

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

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


推荐阅读