jsondocker-composemqttmosquittofiware

IoTAgent (JSON) over MQTT doesn't receive measurements from mosquitto


Goal: to use the IoTAgent (JSON) provided by FIWARE with the MQTT transport protocol. In particular, I would like to provision a service group rather than individual devices, such that anonymous devices can send their measurements to the IoTAgent via the Mosquitto Broker.

Problem: Mosquitto Broker receives messages (sent by an MQTT publisher) but IoTAgent does not. Both are on the same network (I used docker compose), so ruled out this could be the reason of the problem.

The docker-compose.yaml file looks like this:

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

The full docker-compose.yaml is available on GitLab repository.

The service group provisioning is shown below:

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

I expect the IoTAgent to receive measurements from anonymous devices as well as mosquitto. Instead, currently, the IoTAgent does not receive the measurements and gives the following error when I provision the service group: DEVICE_GROUP_NOT_FOUND.

The logs are shown on GitLab repository

I can't figure out the problem.


Solution

  • On the assumption you have provisioned a device as follows:

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

    You will need to post your data to the /json/<api-key>/<device-id>/attrs topic. It is important to include both the correct protocol json and the correct <api-key> - the message body is something like {"c": 1}.

    This can be used to test the IoT Agent South Port without an actual device - assuming it works, you can then check that the Device is posting to the correct topic.