chirpstack / chirpstack-mqtt-forwarder

ChirpStack MQTT Forwarder is a forwarder which can be installed on the gateway to forward LoRa data over MQTT.
MIT License
21 stars 13 forks source link

failed to read gateway id from concentratord inside containers #43

Closed Sheng2216 closed 1 year ago

Sheng2216 commented 1 year ago

Hello, I have put the concentratord and chirpstack-mqtt-forwarder binaries into two separate containers and created a docker-compose file to ease deployment. However, the chirpstack-mqtt-forwarder container always stops at the 'reading gateway id' step. When I put both binaries in the same container, it works well and the chirpstack-mqtt-forwarder is able to read the gateway ID

I'm new to ZeroMQ, but I'm wondering if the issue is related to the fact that although the two containers are in the same network, ZeroMQ is using a different IP address for communication. Can you please help me understand why the chirpstack-mqtt-forwarder container is unable to read the gateway ID when it is in a separate container from the concentratord container? Thank you.

here is the docker-compose log:

fish_01-mqtt_forwarder_local-1 | 2023-07-04T09:17:54.776Z INFO [chirpstack_mqtt_forwarder] Starting ChirpStack MQTT Forwarder (version: 4.1.0, docs: https://www.chirpstack.io/) fish_01-mqtt_forwarder_local-1 | 2023-07-04T09:17:54.776Z INFO [chirpstack_mqtt_forwarder::backend] Setting up ChirpStack Concentratord backend fish_01-mqtt_forwarder_local-1 | 2023-07-04T09:17:54.776Z INFO [chirpstack_mqtt_forwarder::backend::concentratord] Setting up ChirpStack Concentratord backend fish_01-mqtt_forwarder_local-1 | 2023-07-04T09:17:54.776Z INFO [chirpstack_mqtt_forwarder::backend::concentratord] Connecting to Concentratord event API, event_url: ipc:///tmp/concentratord_event fish_01-mqtt_forwarder_local-1 | 2023-07-04T09:17:54.778Z INFO [chirpstack_mqtt_forwarder::backend::concentratord] Connecting to Concentratord command API, command_url: ipc:///tmp/concentratord_command fish_01-mqtt_forwarder_local-1 | 2023-07-04T09:17:54.778Z INFO [chirpstack_mqtt_forwarder::backend::concentratord] Reading gateway id fish_01-concentratord_slot2-1 | 2023-07-04T09:18:10.782Z INFO [libconcentratord::events] Publishing stats event, rx_received: 0, rx_received_ok: 0, tx_received: 0, tx_emitted: 0 fish_01-concentratord_slot2-1 | 2023-07-04T09:18:13.978Z DEBUG [chirpstack_concentratord_sx1302::wrapper] Could not get GPS epoch, uplink_id: 981833365, error: gps_ref_valid = false fish_01-concentratord_slot2-1 | 2023-07-04T09:18:13.979Z DEBUG [chirpstack_concentratord_sx1302::wrapper] Could not get GPS time, uplink_id: 981833365, error: gps_ref_valid = false fish_01-concentratord_slot2-1 | 2023-07-04T09:18:13.979Z INFO [chirpstack_concentratord_sx1302::handler::uplink] Frame received, uplink_id: 981833365, count_us: 364316853, freq: 922900000, bw: 125000, mod: LoRa, dr: SF10, ftime_received: false, ftime_ns: 0 fish_01-concentratord_slot2-1 | 2023-07-04T09:18:40.787Z INFO [libconcentratord::events] Publishing stats event, rx_received: 1, rx_received_ok: 1, tx_received: 0, tx_emitted: 0 fish_01-concentratord_slot2-1 | 2023-07-04T09:19:10.789Z INFO [libconcentratord::events] Publishing stats event, rx_received: 0, rx_received_ok: 0, tx_received: 0, tx_emitted: 0

and here is the docker-compose file(The Dockerfile only copies the compiled binaries into the container):

version: "3"

services:

  concentratord_slot2:
    #image: chirpstack_concentratord:0.1
    # or comment out image: and build it yourself
    build:
      context: ./chirpstack_concentratord_sx1302_docker/
      dockerfile: ./Dockerfile
    restart: unless-stopped
    privileged: true
    networks:
      - zeromq_network
    volumes:
      - ./configuration/concentratord/concentratord_RAK7391_slot2.toml:/app/concentratord.toml:ro

  mqtt_forwarder_local:
    #image: chirpstack_mqtt_forwarder:0.1
    # or comment out image: and build it yourself
    build:
      context: ./chirpstack_mqtt_forwarder_docker/
      dockerfile: ./Dockerfile
    restart: unless-stopped
    privileged: true
    ports:
      - "1700:1700/udp"
    networks:
      - zeromq_network
    volumes:
      - ./configuration/chirpstack-mqtt-forwarder/chirpstack-mqtt-forwarder-local.toml:/app/chirpstack-mqtt-forwarder.toml:ro
    depends_on:
      # - chirpstack
      - concentratord_slot2

networks:
  zeromq_network:
    driver: bridge

Thank you in advance. I appreciate your help with this.

brocaar commented 1 year ago

Hello, The MQTT Forwarder tries to connect to the Concentratord using a socket. By default these are the sockets created by the Concentratord:

concentratord.toml:

  # Configuration for the (ZeroMQ based) API.
  [concentratord.api]
    # Event PUB socket bind.
    event_bind="ipc:///tmp/concentratord_event"

    # Command REP socket bind.
    command_bind="ipc:///tmp/concentratord_command"

chirpstack-mqtt-forwarder.toml:

  # ChirpStack Concentratord backend configuration.
  [backend.concentratord]

    # Event API URL.
    event_url="ipc:///tmp/concentratord_event"

    # Command API URL.
    command_url="ipc:///tmp/concentratord_command"

I have not tested this, but I expect the solution would be to have a shared volume between the two containers which can be used by the Concentratord for creating the sockets, and for the MQTT Forwarder to connect to the Concentratord using these sockets.

Sheng2216 commented 1 year ago

I have not tested this, but I expect the solution would be to have a shared volume between the two containers which can be used by the Concentratord for creating the sockets, and for the MQTT Forwarder to connect to the Concentratord using these sockets.

it works, thank you!

version: "3"
services:
  concentratord_slot2:
    build:
      context: ./chirpstack_concentratord_sx1302_docker/
      dockerfile: ./Dockerfile
    restart: unless-stopped
    volumes:
      # Mount the shared volume for the socket files
      - concentratord_sockets:/tmp/
      - ./configuration/concentratord/concentratord.toml:/app/concentratord.toml:ro

  mqtt_forwarder_local:
    build:
      context: ./chirpstack_mqtt_forwarder_docker/
      dockerfile: ./Dockerfile
    restart: unless-stopped
    ports:
      - "1700:1700/udp"
    volumes:
    # Mount the shared volume for the socket files
      - concentratord_sockets:/tmp/
      - ./configuration/chirpstack-mqtt-forwarder/chirpstack-mqtt-forwarder-local.toml:/app/chirpstack-mqtt-forwarder.toml:ro
    depends_on:
    # - chirpstack
      - concentratord_slot2

volumes:
  concentratord_sockets: