【问题标题】:Command doesn't forward from FIWARE JSON Agent toward the Broker MQTT命令不会从 FIWARE JSON 代理转发到代理 MQTT
【发布时间】:2018-10-20 17:04:39
【问题描述】:

我已经使用 docker 部署了物联网堆栈。这些是使用过的容器:

  • fiware/orion:1.13.0
  • fiware/iotagent-json:1.8.0
  • eclipse-mosquitto:1.4.12
  • [问题未涉及的其他容器...]

我在代理上注册了以下设备:

{
     "device_id": "t3",
     "service": "lmobile",
     "service_path": "/lmobile_Industry",
     "entity_name": "t3",
     "entity_type": "Device",
     "endpoint": "tcp://<mqttborker_publicip>:<port>",
     "transport": "MQTT",
     "attributes": [{
                "object_id": "led",
                "name": "led",
                "type": "text"
     }],
     "lazy": [],
     "commands": [{
                "object_id": "c",
                "name": "c",
                "type": "Command"
     }],
     "static_attributes": [
                      ....
     ],
     "protocol": "JSON"
}

并且已在 OCB 上正确创建了相应的实体,当我在 mqttbroker 上发布新度量时,在主题 /&lt;apikey&gt;/t3/attrs 下,该度量已正确转发到 OCB。

为了向设备发送命令 c,我在 OCB 上发送以下 updateContext:

curl -s -X POST http://<orionhost>:1026/v1/updateContext
       -H 'accept: application/json'
       -H 'cache-control: no-cache' 
       -H 'content-type: application/json'
       -H 'fiware-service: lmobile'
       -H 'fiware-servicepath: /lmobile_Industry'
       -d '{
             "contextElements": [
                 {
                    "type": "Device",
                     "isPattern": "false",
                     "id": "t3",
                     "attributes": [
                       {
                         "name":"c",
                         "type":"Command",
                         "value":100
                       }
                     ]
                 }
             ],
             "updateAction": "UPDATE"
         }'

我收到以下错误响应:

{
     "errorCode": {
         "code": "404",
         "reasonPhrase": "No context element found",
         "details": "invalid context provider response"
     }
}

在 OCB 日志中,我可以看到以下警告消息: time=Thursday 18 Oct 08:55:54 2018.431Z | lvl=WARN | corr=N/A | trans=N/A | from=N/A | srv=N/A | subsrv=N/A | comp=Orion | op=postQueryContext.cpp[169]:queryForward | msg=Other Error (context provider response to QueryContext is empty)。 无论如何,updateContext 已正确转发给 Agent。

在代理日志中(在 DEBUG 中)我可以看到以下内容:

iotstack_agent-json.1.xyz@xerus-1    | time=2018-10-18T09:02:33.975Z | lvl=DEBUG | corr=8d2864ec-d2b4-11e8-b445-02420aff0161 | trans=de5680e7-0727-4577-ac44-ddeb59df1f31 | op=IoTAgentNGSI.GenericMiddlewares | srv=lmobile | subsrv=/lmobile_Industry | msg=Request for path [/updateContext] from [<agent_publicip>:<port>] | comp=IoTAgent
iotstack_agent-json.1.xyz@xerus-1    | time=2018-10-18T09:02:33.976Z | lvl=DEBUG | corr=8d2864ec-d2b4-11e8-b445-02420aff0161 | trans=de5680e7-0727-4577-ac44-ddeb59df1f31 | op=IoTAgentNGSI.GenericMiddlewares | srv=lmobile | subsrv=/lmobile_Industry | msg=Body:
iotstack_agent-json.1.xyz@xerus-1    |
iotstack_agent-json.1.xyz@xerus-1    | {
iotstack_agent-json.1.xyz@xerus-1    |     "contextElements": [
iotstack_agent-json.1.xyz@xerus-1    |         {
iotstack_agent-json.1.xyz@xerus-1    |             "type": "Device",
iotstack_agent-json.1.xyz@xerus-1    |             "isPattern": "false",
iotstack_agent-json.1.xyz@xerus-1    |             "id": "t3",
iotstack_agent-json.1.xyz@xerus-1    |             "attributes": [
iotstack_agent-json.1.xyz@xerus-1    |                 {
iotstack_agent-json.1.xyz@xerus-1    |                     "name": "c",
iotstack_agent-json.1.xyz@xerus-1    |                     "type": "Command",
iotstack_agent-json.1.xyz@xerus-1    |                     "value": "100"
iotstack_agent-json.1.xyz@xerus-1    |                 }
iotstack_agent-json.1.xyz@xerus-1    |             ]
iotstack_agent-json.1.xyz@xerus-1    |         }
iotstack_agent-json.1.xyz@xerus-1    |     ],
iotstack_agent-json.1.xyz@xerus-1    |     "updateAction": "UPDATE"
iotstack_agent-json.1.xyz@xerus-1    | }
iotstack_agent-json.1.xyz@xerus-1    |
iotstack_agent-json.1.xyz@xerus-1    |  | comp=IoTAgent
iotstack_agent-json.1.xyz@xerus-1    | time=2018-10-18T09:02:33.978Z | lvl=DEBUG | corr=8d2864ec-d2b4-11e8-b445-02420aff0161 | trans=de5680e7-0727-4577-ac44-ddeb59df1f31 | op=IoTAgentNGSI.DomainControl | srv=lmobile | subsrv=/lmobile_Industry | msg=response-time: 6 | comp=IoTAgent

在这里我没有看到警告或错误,但没有任何命令被转发到任何主题的 MQTT 代理(我订阅了命令/&lt;apikey&gt;/t3/cmd 的特定主题和使用通配符# 订阅的所有主题)。

【问题讨论】:

    标签: mqtt iot fiware fiware-orion


    【解决方案1】:

    @fgalan 是正确的 - 在为 MQTT 配置服务组时不需要 endpoint 字段

    curl -iX POST \
      'http://localhost:4041/iot/services' \
      -H 'Content-Type: application/json' \
      -H 'fiware-service: openiot' \
      -H 'fiware-servicepath: /' \
      -d '{
     "services": [
       {
         "apikey":      "4jggokgpepnvsb2uv4s40d59ov",
         "cbroker":     "http://orion:1026",
         "entity_type": "Thing",
         "resource":    ""
       }
     ]
    }'
    

    但是,必须正确配置 config.json 文件以与 MQTT 代理通信。

    我个人会使用 docker-compose 并使用 Docker 环境变量分配值,但也可以直接编辑 config.json 文件:

     environment:
         - "IOTA_MQTT_HOST=mosquitto" # The host name of the MQTT Broker
         - "IOTA_MQTT_PORT=1883" # The port the MQTT Broker is listening on to receive topics
    

    这是ENV变量和config.json设置之间的映射:

    • IOTA_MQTT_HOST - mqtt.host
    • IOTA_MQTT_PORT - mqtt.port
    • IOTA_MQTT_USERNAME - mqtt.username
    • IOTA_MQTT_PASSWORD - mqtt.password
    • IOTA_MQTT_QOS - mqtt.qos

    注意cbroker 也是一个可选属性——如果不是 提供,物联网代理使用默认上下文代理 URL,如 配置文件

    用于通过 MQTT 配置设备的 Tutorial 使用 Ultralight IoT 代理,但 JSON IoT 代理应该以相同的方式工作。

    【讨论】:

      【解决方案2】:

      不完全确定,但可能是配置阶段的问题。以tcp:// 开头的endpoint 对我来说有点奇怪......

      更详细的,看ths piece of documentation我看了:

      示例显示比较 [MQTT 规定] 有两个不同之处 使用 HTTP 配置:

      • 缺少“端点”字段
      • 存在“传输”字段,其值必须为“MQTT”。

      所以我知道您在配置时根本不应该使用 endpoint 字段。

      【讨论】:

      • 嗨弗加兰。谢谢你的回复。我试图发布没有端点字段的相同设备。但什么都没有改变
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-10
      • 2017-07-26
      • 1970-01-01
      • 2017-02-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多