iotagent-node-lib icon indicating copy to clipboard operation
iotagent-node-lib copied to clipboard

No CMD attributes added when sending push commands (using `endpoint`)

Open mapedraza opened this issue 1 year ago • 8 comments

IoT Agent Node Lib version the issue has been seen with

4.1.0

Bound or port used (API interaction)

Southbound (Devices data API), Northbound (Provision API and NGSI Interactions)

NGSI version

NGSIv2

Are you running a container?

Yes, I am using a contaner (Docker, Kubernetes...)

Image type

normal

Expected behaviour you didn't see

No _info and _status added to the entity when sending push commands (using endpoint parameter in provision)

Steps to reproduce the problem

Group provision

curl --location 'http://localhost:4041/iot/services' \
--header 'Fiware-Service: test' \
--header 'Fiware-ServicePath: /test240125' \
--header 'X-Auth-Token: null' \
--header 'Content-Type: application/json' \
--data '{
    "services": [
        {
            "resource": "/iot/json",
            "apikey": "123456789100",
            "type": "dev",
            "cbHost": "http://orion:1026",
            "static_attributes": [
                {
                    "name": "operationalStatus",
                    "type": "Text",
                    "value": "ok"
                }
            ],
            "commands": []
        }
    ]
}'

Dev provision

curl --location 'http://localhost:4041/iot/devices' \
--header 'Fiware-Service: test' \
--header 'Fiware-ServicePath: /test240125' \
--header 'X-Auth-Token: null' \
--header 'Content-Type: application/json' \
--data '{
    "devices": [
        {
            "protocol": "IoTA-JSON",
            "explicitAttrs": false,
            "device_id": "dev2",
            "apikey": "123456789100",
            "entity_name": "dev2",
            "entity_type": "Device",
            "transport": "HTTP",
            "lazy": [],
            "commands": [ 
                {
                    "name": "ping",
                    "type": "command"
                }
            ],
            "endpoint": "https://webhook.site/5425edee"
        }
    ]
}'

Triggering cmd

curl -L -X PUT 'http://localhost:1026/v2/entities/dev2/attrs/ping?type=Device' \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /test240125' \
-H 'Content-Type: application/json' \
-d '{
      "type" : "command",
      "value" : "123"
}'

Then, no _info and _status attributes added to CB.

Expected _status = DELIVERED if worked the HTTP request to be included into the entity in order to align with polling commands.

After confirming the command, this means the following request:

curl --location 'http://localhost:7896/iot/json/commands?k=123456789100&i=dev2' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '{"ping":"ping_ok"}'

entity is updated with info and status attributes as follows:

    "ping_info": {
      "type": "commandResult",
      "value": "ping_ok",
      "metadata": {
        "TimeInstant": {
          "type": "DateTime",
          "value": "2024-01-25T10:09:23.144Z"
        }
      }
    },
    "ping_status": {
      "type": "commandStatus",
      "value": "OK",
      "metadata": {
        "TimeInstant": {
          "type": "DateTime",
          "value": "2024-01-25T10:09:23.144Z"
        }
      }
    }

mapedraza avatar Jan 25 '24 10:01 mapedraza

IMHO depending on what is done by https://webhook.site/5425edee, in my case a request-bin service the command_status in entity will be updated. In a default case, request-bin is receiving command and doing nothing, and then iotagent mark command_status as PENDING.

Which response is sending https://webhook.site/5425edee endpoint ? 200? 204?

AlvaroVega avatar Jan 25 '24 10:01 AlvaroVega

It retruns a 200 code.

In any case, the <command>_status attribute should be present, changing the value according with the response (2XX, 4XX or timeout)

mapedraza avatar Jan 25 '24 12:01 mapedraza

Is this URL right ?

curl -L -X PUT 'http://localhost:1026/v2/entities/dev2/attrs/ring?type=Device' \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /test240125' \
-H 'Content-Type: application/json' \
-d '{
      "type" : "command",
      "value" : "123"
}'

@mapedraza ring or ping ?

AlvaroVega avatar Jan 25 '24 15:01 AlvaroVega

@AlvaroVega ping, was a typo

mapedraza avatar Jan 26 '24 08:01 mapedraza

Hi @mapedraza ,

I was trying to reproduce the issue to fix it. But i am facing error while triggering command.

curl -L -X PUT 'http://localhost:1026/v2/entities/dev2/attrs/ping?type=Device' \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /test240125' \
-H 'Content-Type: application/json' \
-d '{
      "type" : "command",
      "value" : "123"
}'

Above API results into below error:

curl -L -X PUT 'http://localhost:1026/v2/entities/dev2/attrs/ping?type=Device'
-H 'fiware-service: test'
-H 'fiware-servicepath: /test240125'
-H 'Content-Type: application/json'
-d '{ "type" : "command", "value" : "123" }' {"error":"NotFound","description":"The requested entity has not been found. Check type and id"}

Could you please help me to reproduce the issue?

Madhu1029 avatar May 21 '24 08:05 Madhu1029

Hi @mapedraza ,

I was trying to reproduce the issue to fix it. But i am facing error while triggering command.

curl -L -X PUT 'http://localhost:1026/v2/entities/dev2/attrs/ping?type=Device' \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /test240125' \
-H 'Content-Type: application/json' \
-d '{
      "type" : "command",
      "value" : "123"
}'

Above API results into below error:

curl -L -X PUT 'http://localhost:1026/v2/entities/dev2/attrs/ping?type=Device' -H 'fiware-service: test' -H 'fiware-servicepath: /test240125' -H 'Content-Type: application/json' -d '{ "type" : "command", "value" : "123" }' {"error":"NotFound","description":"The requested entity has not been found. Check type and id"}

Could you please help me to reproduce the issue?

Could you share your share the steps you used till arriving to that response? Please, share also IoT Agent and Context Broker version

mapedraza avatar May 22 '24 07:05 mapedraza

Hi @mapedraza ,

I have followed below steps: 1. Group Provision

curl --location 'http://localhost:4041/iot/services' \
--header 'Fiware-Service: test' \
--header 'Fiware-ServicePath: /test240125' \
--header 'X-Auth-Token: null' \
--header 'Content-Type: application/json' \
--data '{
    "services": [
        {
            "resource": "/iot/json",
            "apikey": "4jggokgpepnvsb2uv4s40d59ov",
            "type": "dev",
            "cbHost": "http://localhost:1026",
            "static_attributes": [
                {
                    "name": "operationalStatus",
                    "type": "Text",
                    "value": "ok"
                }
            ],
            "commands": []
        }
    ]
}'

2. Device Provision

curl --location 'http://localhost:4041/iot/devices' \
--header 'Fiware-Service: test' \
--header 'Fiware-ServicePath: /test240125' \
--header 'X-Auth-Token: null' \
--header 'Content-Type: application/json' \
--data '{
    "devices": [
        {
            "protocol": "IoTA-JSON",
            "explicitAttrs": false,
            "device_id": "dev2",
            "apikey": "4jggokgpepnvsb2uv4s40d59ov",
            "entity_name": "dev2",
            "entity_type": "Device",
            "transport": "HTTP",
            "lazy": [],
            "commands": [ 
                {
                    "name": "ping",
                    "type": "command"
                }
            ],
            "endpoint": "http://localhost:3001"
        }
    ]
}'

3. Trigger Command

curl -L -X PUT 'http://localhost:1026/v2/entities/dev2/attrs/ping?type=Device' \
-H 'fiware-service: test' \
-H 'fiware-servicepath: /test240125' \
-H 'Content-Type: application/json' \
-d '{
      "type" : "command",
      "value" : "123"
}'

After Step 3, I am facing below error: {"error":"NotFound","description":"The requested entity has not been found. Check type and id"}

Note: I have started dummy IoT Devices configuration using below:

tutorial:
    image: quay.io/fiware/tutorials.context-provider
    hostname: iot-sensors
    container_name: fiware-tutorial
    networks:
        - default
    expose:
        - '3000'
        - '3001'
    ports:
        - '3000:3000'
        - '3001:3001'
    environment:
        - 'DEBUG=tutorial:*'
        - 'PORT=3000'
        - 'IOTA_HTTP_HOST=iot-agent'
        - 'IOTA_HTTP_PORT=7896'
        - 'DUMMY_DEVICES_PORT=3001'
        - 'DUMMY_DEVICES_API_KEY=4jggokgpepnvsb2uv4s40d59ov'
        - 'DUMMY_DEVICES_TRANSPORT=HTTP'

Madhu1029 avatar May 27 '24 07:05 Madhu1029

Hi @mapedraza ,

I have followed below steps: 1. Group Provision

...

Note: I have started dummy IoT Devices configuration using below:

tutorial:
    image: quay.io/fiware/tutorials.context-provider
    hostname: iot-sensors
    container_name: fiware-tutorial
    networks:
        - default
    expose:
        - '3000'
        - '3001'
    ports:
        - '3000:3000'
        - '3001:3001'
    environment:
        - 'DEBUG=tutorial:*'
        - 'PORT=3000'
        - 'IOTA_HTTP_HOST=iot-agent'
        - 'IOTA_HTTP_PORT=7896'
        - 'DUMMY_DEVICES_PORT=3001'
        - 'DUMMY_DEVICES_API_KEY=4jggokgpepnvsb2uv4s40d59ov'
        - 'DUMMY_DEVICES_TRANSPORT=HTTP'

Hi @Madhu1029 . I am not able to see which version of Orion and IoTA you are using. Please, try with latest releases:

telefonicaiot/fiware-orion:3.12.0

and

telefonicaiot/iotagent-json:3.4.0

mapedraza avatar May 27 '24 09:05 mapedraza