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

时间:2019-06-26 16:02:22

标签: fiware fiware-orion

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

1 个答案:

答案 0 :(得分:1)

问题是由于使用了POST动词(在POST /v2/entities/lamp1/attrs?type=lamp中)来发送命令。 POST具有创建语义,因此它将ping属性添加到实体,而不是将其转发到IOTA。因此,该命令永远不会到达IOTA,因此IOTA永远不会在MQTT代理中发布。在this section of the documentation的“重要说明”中对此进行了更详细的说明。

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

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