简体   繁体   English

MQTT 上的 IotAgent UltraLight 不处理来自 MQTT 代理的值

[英]IotAgent UltraLight over MQTT is not processing values from MQTT broker

I am following the tutorial under: https://github.com/FIWARE/tutorials.IoT-over-MQTT我正在关注以下教程: https : //github.com/FIWARE/tutorials.IoT-over-MQTT

Steps 1 to 3 are followed exactly as in the tutorial (working fine), in Step 4 I am using mosquitto_pub to publish the message to the MQTT broker.完全按照教程中的步骤执行步骤 1 到步骤 3(工作正常),在步骤 4 中,我使用 mosquitto_pub 将消息发布到 MQTT 代理。

The MQTT message does not get processed by the IotAgent, however.但是,IotAgent 不会处理 MQTT 消息。 I can see this when I try to retrieve the data from the Context Broker as in Step 5.当我尝试从 Context Broker 检索数据时,我可以看到这一点,如步骤 5 所示。

Using the debugger with:使用调试器:

docker exec -it [IOTAGENT CONTAINER] pm2 monit

also shows nothing happening when the MQTT message is published.当 MQTT 消息发布时,也没有显示任何事情发生。 I have tried the messaging formats below:我尝试了以下消息格式:

mosquitto_pub -t "/4jggokgpepnvsb2uv4s40d59ov/motion001/attrs" -m "c|1" 
mosquitto_pub -t /4jggokgpepnvsb2uv4s40d59ov/motion001/attrs -m '{"c":1}'

The Mosquitto broker is running and can be subscribed to. Mosquitto 代理正在运行并且可以订阅。 Am I missing a parameter?我错过了一个参数吗? What could be the reason that the IotAgent is not working as expected? IotAgent 未按预期工作的原因可能是什么? I had tested the setup successfully some months ago, but unfortunately the testing parameters are not available anymore.几个月前我已经成功测试了设置,但不幸的是,测试参数不再可用。

This is most likely a docker networking issue, within the tutorial all of the components (including the MQTT Broker) have been placed into the same docker network and hence can communicate with one another.这很可能是 docker 网络问题,在本教程中,所有组件(包括 MQTT Broker)都已放置在同一个 docker 网络中,因此可以相互通信。 My guess is that this is not the case for your current set up.我的猜测是,您当前的设置并非如此。

The IoT Agent section of the Docker Compose File includes the IOTA_MQTT_HOST=mosquitto environment variable which is listening to the MQTT Broker called mosquitto in the same network. Docker Compose 文件的 IoT 代理部分包含IOTA_MQTT_HOST=mosquitto环境变量,该变量正在侦听同一网络中名为mosquitto的 MQTT Broker。

To send a measurement via MQTT, you will need to invoke the MQTT publisher from within the same network.要通过 MQTT 发送测量,您需要从同一网络内调用 MQTT 发布者。

docker run -it --rm --name mqtt-publisher --network \
  fiware_default efrecon/mqtt-client pub -h mosquitto -m "c|1" \
  -t "/4jggokgpepnvsb2uv4s40d59ov/motion001/attrs"

Alternatively for a real installation you must alter the IOTA_MQTT_HOST value to refer to the real location of the MQTT Broker.或者,对于真实安装,您必须更改IOTA_MQTT_HOST值以引用 MQTT Broker 的真实位置。

With this edited docker compose file from https://github.com/FIWARE/tutorials.IoT-over-MQTT/blob/master/docker-compose.yml , I was able to run my tests successfully.使用来自https://github.com/FIWARE/tutorials.IoT-over-MQTT/blob/master/docker-compose.yml 的这个编辑过的 docker compose 文件,我能够成功运行我的测试。 Deployment command:部署命令:

docker stack deploy -c docker-compose.yml fiware

docker-compose.yml: docker-compose.yml:

version: "3.5"
services:
  orion:
    image: fiware/orion
    hostname: orion
    container_name: fiware-orion
    depends_on:
      - mongo-db
    networks:
      - default
    ports:
      - "1026:1026"
    command: -dbhost mongo-db -logLevel DEBUG
    healthcheck:
      test: curl --fail -s http://orion:1026/version || exit 1

  iot-agent:
    image: fiware/iotagent-ul
    hostname: iot-agent
    container_name: fiware-iot-agent
    depends_on:
      - mongo-db
      - mosquitto
    networks:
      - default
    expose:
      - "4061"
      - "7896"
    ports:
      - "4061:4061"
      - "7896:7896"
    environment:
      - IOTA_CB_HOST=orion # name of the context broker to update context
      - IOTA_CB_PORT=1026 # port the context broker listens on to update context
      - IOTA_NORTH_PORT=4061
      - IOTA_REGISTRY_TYPE=mongodb #Whether to hold IoT device info in memory or in a database
      - IOTA_LOG_LEVEL=DEBUG # The log level of the IoT Agent
      - IOTA_TIMESTAMP=true # Supply timestamp information with each measurement
      - IOTA_CB_NGSI_VERSION=v2 # use NGSIv2 when sending updates for active attributes
      - IOTA_AUTOCAST=true # Ensure Ultralight number values are read as numbers not strings
      - IOTA_MONGO_HOST=mongo-db # The host name of MongoDB
      - IOTA_MONGO_PORT=27017 # The port mongoDB is listening on
      - IOTA_MONGO_DB=iotagentul # The name of the database used in mongoDB
      - 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
      - IOTA_DEFAULT_RESOURCE= # Default is blank. I'm using MQTT so I don't need a resource
      - IOTA_PROVIDER_URL=http://iot-agent:4061
    healthcheck:
      test: curl --fail -s http://iot-agent:4061/iot/about || exit 1

  mongo-db:
    image: mongo:3.6
    hostname: mongo-db
    container_name: db-mongo
    expose:
      - "27017"
    ports:
      - "27017:27017" # localhost:27017
    networks:
      - default
    command: --bind_ip_all --smallfiles
    volumes:
      - mongo-db:/data

  mosquitto:
    image: eclipse-mosquitto
    hostname: mosquitto
    container_name: mosquitto
    expose:
      - "1883"
      - "9001"
    ports:
      - "1883:1883"
      - "9001:9001"
    volumes:
      - ./mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf
    networks:
      - default
networks:
  default:
    ipam:
      config:
        - subnet: 172.18.1.0/24

volumes:
  mongo-db: ~

These are the successfully running steps:这些是成功运行的步骤:

0) health check 0) 健康检查

curl http://localhost:4061/iot/about

1) create service group 1)创建服务组

curl -iX POST \
  'http://localhost:4061/iot/services' \
  -H 'Content-Type: application/json' \
  -H 'fiware-service: testservice' \
  -H 'fiware-servicepath: /iot_ul' \
  -d '{
 "services": [
   {
     "apikey":      "hallo",
     "cbroker":     "http://orion:1026",
     "entity_type": "multiSensor",
     "resource":    "/iot/d"
   }
 ]
}'

2) create a sensor 2)创建传感器

curl -X POST \
  'http://localhost:4061/iot/devices' \
  -H "Content-Type: application/json" \
  -H "fiware-service: testservice" \
  -H "fiware-servicepath: /iot_ul" \
  -d '{
  "devices": [
    {
      "device_id": "sensor01",
      "entity_name": "LivingRoomSensor1",
      "entity_type": "multiSensor",
      "protocol":    "PDI-IoTA-UltraLight",
      "transport":   "MQTT",
      "attributes": [
        { "object_id": "t", "name": "Temperature", "type": "Integer" },
        { "object_id": "l", "name": "Luminosity", "type": "Integer" }
      ]
    }
  ]
}' 

3) update values via curl 3) 通过 curl 更新值

curl --location --request POST 'http://localhost:7896/iot/d?i=sensor01&k=hallo' \
--header 'Content-Type: text/plain' \
--header 'fiware-service: testservice' \
--header 'fiware-servicepath: /iot_ul' \
--data-raw 't|1|l|3'

4) check whether value was updated 4) 检查值是否更新

curl -X POST -H "Content-Type: application/json" -H "Accept: application/json" -H "Fiware-Service: testservice" -H "Fiware-ServicePath: /iot_ul" -d '{
    "entities": [
        {
            "isPattern": "false",
            "id": "LivingRoomSensor1",
            "type": "multiSensor"
        }
    ]
}' 'http://localhost:1026/v1/queryContext'

5) update value over mqtt (works also from other machine - add parameters -h "hostaddress") 5) 通过 mqtt 更新值(也可以从其他机器运行 - 添加参数 -h "hostaddress")

mosquitto_pub  -m "t|2|l|5" -t "/hallo/sensor01/attrs"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM