通过 MQTT 的 IoTAgent (JSON) 未接收来自 mosquitto 的测量结果

问题描述 投票:0回答:2

目标:使用FIWARE提供的IoTAgent(JSON)和MQTT传输协议。特别是,我想提供一个服务组而不是单个设备,以便匿名设备可以通过 Mosquitto Broker 将其测量结果发送到 IoTAgent。

问题:Mosquitto Broker 接收消息(由 MQTT 发布者发送),但 IoTAgent 不接收。两者都在同一网络上(我使用了 docker compose),因此排除了这可能是问题的原因。

docker-compose.yaml 文件如下所示:

version: "3.5"
services:
  mosquitto:
    image: eclipse-mosquitto:1.6.14
    hostname: mosquitto
    container_name: mosquitto
    expose:
      - "1883"
      - "9001"
    ports:
      - "1883:1883"
      - "9001:9001"
    networks:
      - default

  iot-agent:
    image: fiware/iotagent-json:latest
    hostname: iot-agent
    container_name: fiware-iot-agent
    depends_on:
      - mongo-db
      - mosquitto
    networks:
      - default
    expose:
      - "4041"
    ports:
      - "4041:4041"
    environment:
      - IOTA_CB_HOST=orion
      - IOTA_CB_PORT=1026
      - IOTA_CB_NGSI_VERSION=ld
      - IOTA_JSON_LD_CONTEXT=http://context/ngsi-context.jsonld
      - IOTA_NORTH_PORT=4041
      - IOTA_MQTT_HOST=mosquitto
      - IOTA_MQTT_PORT=1883
      - IOTA_MQTT_QOS=1
      - IOTA_MQTT_KEEPALIVE=60
      - IOTA_DEFAULT_RESOURCE= # Default is blank. I'm using MQTT so I don't need a resource
      - IOTA_REGISTRY_TYPE=mongodb
      - IOTA_MONGO_HOST=mongo-db
      - IOTA_MONGO_PORT=27017
      - IOTA_MONGO_DB=iotagentjson
      - IOTA_LOG_LEVEL=DEBUG
      - IOTA_TIMESTAMP=true
      - IOTA_AUTOCAST=true
      - IOTA_FALLBACK_TENANT=openiot

完整的 docker-compose.yaml 可在 GitLab 存储库上获取。

服务组配置如下所示:

{
    "services": [
        {
            "apikey": "4jggokgpepnvsb2uv4s40d59ov",
            "entity_type": "TrafficFlowObserved",
            "resource": "",
            "expressionLanguage": "jexl",
            "attributes": [
                {"name": "id", "type": "Text", "expression": "'urn:ngsi-ld:TrafficFlowObserved:'+idelem"},
                {"name": "dateObserved", "type": "Text", "expression": "fecha_hora_inicio|toisodate+'/'+fecha_hora_finalizacion|toisodate"},
                {"object_id": "intensidad", "name": "intensity", "type": "Number"}
            ]
        }
    ]   
}

我希望 IoTAgent 能够接收来自匿名设备和蚊子的测量结果。相反,当前,当我配置服务组时,IoTAgent 不会收到测量结果并给出以下错误:DEVICE_GROUP_NOT_FOUND。

日志显示在 GitLab 存储库

我无法找出问题所在。

json docker-compose mqtt mosquitto fiware
2个回答
0
投票

假设您已按如下方式配置设备:

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":    ""
   }
 ]
}'
curl -iX POST \
  'http://localhost:4041/iot/devices' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: openiot' \
  -H 'fiware-servicepath: /' \
  -d '{
 "devices": [
   {
     "device_id":   "motion001",
     "entity_name": "urn:ngsi-ld:Motion:001",
     "entity_type": "Motion",
     "protocol":    "PDI-IoTA-UltraLight",
     "transport":   "MQTT",
     "timezone":    "Europe/Berlin",
     "attributes": [
       { "object_id": "c", "name": "count", "type": "Integer" }
     ]
   }
 ]
}'

您需要将数据发布到

/json/<api-key>/<device-id>/attrs
主题。包含正确的 协议
json
和正确的
<api-key>
非常重要 - 消息正文类似于
{"c": 1}

这可用于在没有实际设备的情况下测试 IoT 代理南端口 - 假设它有效,然后您可以检查设备是否发布到正确的主题。


-1
投票

您能否向我展示一个关于如何使用我看到您使用的 mosquitto 在 /json/api-key/device-id/attrs 主题中发布数据的示例? 谢谢 我只是尝试 mosquitto_pub -t /json/4jggokgpepnvsb2uv4s40d59ov/motion001/attrs -m "c|1" 但是当我尝试在 mongodb 中找到变量时我看不到它。

© www.soinside.com 2019 - 2024. All rights reserved.