命令不会从FIWARE JSON代理转发到Broker MQTT

时间:2018-10-20 17:04:39

标签: mqtt iot fiware fiware-orion

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

  • 固件/猎户座: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上发布新度量时,在主题/<apikey>/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会正确转发到代理。

在代理日志(在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 Broker(我通过使用通配符{既订阅了命令/<apikey>/t3/cmd的特定主题,也订阅了所有主题。 {1}}。

2 个答案:

答案 0 :(得分: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 Broker对话至关重要。

我个人将使用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 Agent,但是JSON IoT Agent应该以相同的方式工作。

答案 1 :(得分:0)

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

更详细地了解ths piece of documentation,我读到了:

  

该示例显示比较[MQTT条款]有两个区别   配备HTTP:

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

因此,我很确定您不应该在置备时完全使用endpoint字段。