【问题标题】:iotagent-json using MQTT not publishing anything when command is sent使用 MQTT 的 iotagent-json 在发送命令时不发布任何内容
【发布时间】:2017-12-21 16:20:41
【问题描述】:

在我的服务器上,我有 Orion 上下文代理和一个在 docker 容器中工作的 IoT 代理。我可以使用 MQTT 协议注册和更新我的实体没有问题。但我希望能够使用 IoT 代理中的命令系统向我的设备发送命令。在Documentation 中,它表示当注册命令时,IoT 代理会在 /apiKey/EntityID/cmd 中发布一些内容。但是,当我这样做时,我没有发布任何内容。实体已正确更新(我可以看到命令的状态变为 PENDING,并且正面 LOG 告诉我一切正常。但我的 MQTT 主题上没有发布任何内容。

这是我的 docker-compose.yml 文件:

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

我这样创建我的实体:

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" } ] }
        ]
    }'

我可以使用以下命令更新我的实体:

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

并创建一个这样的命令:

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" } 
    ]
    }
]}'

我订阅了:

mosquitto_sub -h 127.23.64.163 -t /# -v

但是当我创建一个命令时,我什么也没看到。

但是,如果我运行:

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

我可以验证命令并在我的实体上观察结果。我唯一的问题是,当我希望在 /apikey/sensor10/cmd 上发布某些内容时,创建命令时没有发布任何内容。知道为什么以及如何解决它吗?

更新 1

我尝试对图像 fiware/iotagent-ul 进行相同的操作,但结果完全相同。没有发布任何内容。

【问题讨论】:

    标签: mqtt iot fiware mosquitto fiware-orion


    【解决方案1】:

    问题在于我如何在 IoT 代理上创建设备。我必须指定传输字段,即 MQTT。所以为了让它工作,我必须创建一个这样的设备:

    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'
    

    现在,当我创建命令时,我在主题 /1234/iotsensor6/cmd 中创建了条目

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-08-15
      • 2014-12-08
      • 2023-03-21
      • 2020-11-27
      • 2013-01-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多