Error when invoke a PATCH command to Orion Context Broker

Viewed 60

We're trying to invoke commands from Orion to IoT Device using PATCH and POST requests, but we're always having the following error:

Error [MANDATORY_PARAMS_NOT_FOUND] handing request: 
Some of the mandatory params weren't found in the request: ["API Key","Device Id","Payload"]

Steps:

  1. Create a "Device Entity" in Orion Context Broker

  2. Provisioning a new Device

  3. Create a Service in IoT JSON Agent

    { "services": [ { "apikey": "my_api_key", "protocol": [ "IoTA-JSON" ], "cbroker": "orion:1026", "entity_type": "Device", "resource": "/iot/json" } ] }

  4. Send a POST request to http://iot-agent-host:4041/v2/op/update to execute a command, via gateway, into the IoT Device (Works OK):

    { "actionType": "update", "entities": [ { "id": "shelly-1pm-test", "type": "Device", "cmd": { "type": "command", "value": { "turn": "off", "idDevice": "device001" } } } ] }

  5. Send a PATCH request to http://context-broker-host:1026/v2/entities/entity-name/attrs to execute a command, via Orion CB, into the IoT Device, getting 204 in the response:

    { "cmd": { "type": "command", "value": { "turn": "off", "idDevice": "98cdac2e6101" } } }

  6. The command is not executed. Viewing the IoT JSON Agent logfile we can see:

[MANDATORY_PARAMS_NOT_FOUND] handing request: Some of the mandatory params weren't found in the request: ["API Key","Device Id","Payload"]

Any ideas?

Thanks in advance

1 Answers

MANDATORY_PARAMS_NOT_FOUND is an error message specific to the IoT Agent for JSON. It is usually invoked by an incoming measure which has failed to supply the necessary anti-spoofing information. It should not occur when a command is sent. You have not supplied the actuator provisioning call, but I assume it is something like this:

curl -L -X POST 'http://localhost:4041/iot/devices' \
-H 'fiware-service: openiot' \
-H 'fiware-servicepath: /' \
-H 'Content-Type: application/json' \
--data-raw '{
  "devices": [
      {
        "device_id": "bell001",
        "entity_name": "urn:ngsi-ld:Bell:001",
        "entity_type": "Bell",
        "protocol": "PDI-IoTA-JSON",
        "transport": "HTTP",
        "endpoint": "http://my-device/iot/bell001",
        "commands": [
            {
                "name": "ring",
                "type": "command"
            }
        ]
    }
  ]
}'

Where http://my-device/iot/bell001 is the listening endpoint of the actuator. At a guess your device is responding to this by sending a response to http://iot-agent/iot/json - probably a GET - specifically a response without i or k or d parameters.

  • i: is the device ID.
  • k: the API Key for the device's service.
  • d: the data payload

If you set the IOTA_LOG_LEVEL=DEBUG, the following transactions should occur:

  1. Incoming Request:
op=IoTAgentNGSI.ContextServer-v2 | from=n/a | srv=openiot | subsrv=/ | msg=Handling v2 update from [iot-agent:4041] | comp=IoTAgent
op=IoTAgentNGSI.ContextServer-v2 | from=n/a | srv=openiot | subsrv=/ | msg={
  "entities": [
    {
      "id": "Bell:001",
      "type": "Bell",
      "ring": {
        "type": "command",
        "value": "",
        "metadata": {}
      }
    }
  ],
  "actionType": "update"
} | comp=IoTAgent
  1. Actuation Request:
op=IoTAgentNGSI.Request | from=n/a | srv=n/a | subsrv=n/a | msg=Options: {
  "url": "http://iot-sensors:3001/iot/bell001",
  "method": "POST",
  "body": "{ring:''}",
  "headers": {
    "fiware-service": "openiot",
    "fiware-servicepath": "/",
    "content-type": "application/json"
  },
  "responseType": "text"
} | comp=IoTAgent
  1. Set status to pending
op=IoTAgentNGSI.Entities-v2 | from=n/a | srv=n/a | subsrv=n/a | msg=Using the following NGSI v2 request:

{
  "url": "http://orion:1026/v2/entities/Bell:001/attrs?type=Bell",
  "method": "PATCH",
  "headers": {
    "fiware-service": "openiot",
    "fiware-servicepath": "/"
  },
  "json": {
    "ring_status": {
      "type": "commandStatus",
      "value": "PENDING",
      "metadata": {
        "TimeInstant": {
          "type": "DateTime",
          "value": "2022-07-12T06:47:59.795Z"
        }
      }
    }

}
  1. If the device responds with 200, set status to OK
op=IoTAgentNGSI.Entities-v2 | from=n/a | srv=openiot | subsrv=/ | msg=Updating device value in the Context Broker at [http://orion:1026/v2/op/update] | comp=IoTAgent
op=IoTAgentNGSI.Entities-v2 | from=n/a | srv=openiot | subsrv=/ | msg=Using the following NGSI v2 request:
2022-07-12T06:47:59.944482296Z 
{
  "url": "http://orion:1026/v2/op/update",
  "method": "POST",
  "headers": {
    "fiware-service": "openiot",
    "fiware-servicepath": "/"
  },
  "json": {
    "actionType": "update",
    "entities": [
      {
        "ring_status": {
          "type": "commandStatus",
          "value": "OK",
          "metadata": {
            "TimeInstant": {
              "type": "DateTime",
              "value": "2022-07-12T06:47:59.942Z"
            }
          }
        },
        "ring_info": {
          "type": "commandResult",
          "value": " ring OK",
          "metadata": {
            "TimeInstant": {
              "type": "DateTime",
              "value": "2022-07-12T06:47:59.942Z"
            }
          }
        }
    ]
  }
}

I'm guessing that your device is responding incorrectly to the actuation request (number 2 in the list)

Related