Search code examples
mqttiotfiwaremosquittofiware-orion

iotagent-json using MQTT not publishing anything when command is sent


On my server I have Orion context broker and an IoT agent working in docker containers. I can register and update my entity using MQTT protocol no problem. But I would like to be able to send command to my device using the command system in the IoT Agent. In the Documentation, it says that when a command is registered, the IoT agent publish something in /apiKey/EntityID/cmd. However, when I do so, I don't have anything published. The entity is updated properly (I can see the status of the command going to PENDING, and positive LOG telling me that everything is OK. But nothing is published on my MQTT topic.

Here is my docker-compose.yml file:

version: '3.3'
services: 
    iot-mongo:
        image: mongo:3.2
        ports:
         - "27017:27017"
        volumes:
         - ./data/mongo:/data/db


    iot-agent:
        image: fiware/iotagent-json
        ports:
         - "4041:4041"
        links:
         - iot-mongo
         - orion
         - mosquitto
        volumes:
            - ./config.js:/opt/iotajson/config.js
    mosquitto:
        image: toke/mosquitto
        ports:
            - "1883:1883"
            - "9001:9001"
    orion:
      image: fiware/orion:1.9.0
      links:
        - iot-mongo
      ports:
        - "1026:1026"
      command: -dbhost iot-mongo

I create my entity like this :

curl -X POST http://127.23.64.163:4041/iot/devices \
-i \
-H "Content-Type: application/json" \
-H "Fiware-Service: proj" \
-H "Fiware-ServicePath: /proj" \
-d ' { "devices": [
        { "device_id": "iotsensor10", "entity_name": "iotsensor10", "entity_type": "sensorping", "timezone": "America/Santiago",
        "commands": [
            { "name": "ping", "type": "command", "value": ""} 
        ],
        "attributes": [ 
            { "object_id": "title", "name": "title", "type": "Text" },
            { "object_id": "percentage", "name": "percentage", "type": "Text" }                  
        ],
        "static_attributes": [ { "name": "att_name", "type": "string", "value": "value" } ] }
        ]
    }'

I can update my entity with the following command:

mosquitto_pub -h 127.23.64.163 -t /1234/iotsensor10/attrs -m '{"title": "mqtttitle", "percentage": "31.5"}'

and create a command like this :

curl --request POST http://127.23.64.163:1026/v1/updateContext \
     -i \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-H "Fiware-Service: proj" \
-H "Fiware-ServicePath: /proj" \
-d ' {"updateAction": "UPDATE", "contextElements": [
    {"id": "iotsensor10", "type": "sensorping", "isPattern": "false", 
    "attributes": [
        {"name": "ping", "type": "command", "value": "ALIVE" } 
    ]
    }
]}'

and I subscribe with :

mosquitto_sub -h 127.23.64.163 -t /# -v

But I see nothing coming when I create a command.

However, if I run :

mosquitto_pub -h 127.23.64.163 -t /1234/iotsensor10/cmdexe -m '{"ping": "kebab"}'

I can validate the command and watch the result on my entity. The only problem I have is that nothing is published when the command is created when I expect something to be published on /apikey/sensor10/cmd . Any idea why and how to fix it?

Update 1

I tried to do the same manipulations with the image fiware/iotagent-ul but I have the exact same result. Nothing is published.


Solution

  • The problem comes from how I create my device on my IoT Agent. I have to specify the transport field, which is MQTT. So to make it work, I have to create a device like this :

    curl -X POST -H "Fiware-Service: MyService" -H "Fiware-ServicePath: /MyService" -H "Content-Type: application/json" -d '{ 
    "devices": [ 
        { 
            "device_id": "iotsensor6", 
            "entity_name": "iotsensor6", 
            "entity_type": "sensorping",
          "transport": "MQTT",
    
    "commands": [ { "name": "ping", "type": "command", "value": ""} ],
            "attributes": [ 
                  { "object_id": "title", "name": "title", "type": "text" },
                  { "object_id": "percentage", "name": "percentage", "type": "text" }                  
            ]
        }
    ]
    }' 'http://127.23.64.163:4041/iot/devices'
    

    and now when I create my command, I have the entry created in the topic /1234/iotsensor6/cmd