chirpstack / chirpstack-docker

Setup ChirpStack using Docker Compose
https://www.chirpstack.io/
MIT License
273 stars 316 forks source link

Error: Setup MQTT integration #77

Open TiannV opened 1 year ago

TiannV commented 1 year ago

git clone from master, and run with docker-compose up,chirpstack connect to MQTT broker failed

chirpstack-docker-chirpstack-1                       | 2023-03-15T03:02:23.580980Z  INFO chirpstack::integration::mqtt: Connecting to MQTT broker server_uri=tcp://mosquitto:1883/ client_id=9281b01d204c43f2 clean_session=false
chirpstack-docker-chirpstack-1                       | Error: Setup MQTT integration
chirpstack-docker-chirpstack-1                       | 
chirpstack-docker-chirpstack-1                       | Caused by:
chirpstack-docker-chirpstack-1                       |     0: Connect to MQTT broker
chirpstack-docker-chirpstack-1                       |     1: [-1] TCP/TLS connect failure
TiannV commented 1 year ago

image

curio77 commented 1 year ago

Same here, on a Raspberry Pi with the docker-compose setup. Everything appears to be in order, the broker is running and reachable from the bare machine, also logs a connection (presumably by the chirpstack service), but the chirpstack service keeps restarting with this error.

Did you manage to solve this in the meantime?

mskram commented 1 year ago

I've had this issue both times setting up Chirpstack in Docker.

I'm not 100% on what actually fixed it, but hopefully I can point you in the right direction.

I think the issue was either caused by firewall, docker networking or hostname lookup.

You should be able to test the connection using:

docker run --network="container:mosquitto" -it --rm efrecon/mqtt-client sub -h mosquitto -p 1883 -t "$SYS" -v

If you get "Connection refused" then check the IP of the mosquitto container and try replacing it in the test command.

docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mosquitto
#192.168.176.2
docker run --network="container:mosquitto" -it --rm efrecon/mqtt-client sub -h 192.168.176.2 -p 1883 -t "$SYS" -v

If you use port mapping for the mosquitto container like

ports:
      - 1883:2883

then you have to point to the internal port in the .toml files and in the above test command.

curio77 commented 1 year ago

Thank you for your helpful response. I'd already tried to rule out issues relating to the host by trying the machine's external IP (but can't say 100% that it wasn't an issue in this regard after all).

Meanwhile, I've had the most peculiar thing happen in that, ever since intermittently downgrading Mosquitto to v1.6 in the compose (without resolving the issue), then reinstating v2, it just works (and does so reliably, also across restarts of the compose).

brocaar commented 1 year ago

Meanwhile, I've had the most peculiar thing happen in that, ever since intermittently downgrading Mosquitto to v1.6 in the compose (without resolving the issue), then reinstating v2, it just works (and does so reliably, also across restarts of the compose).

Not sure if that is peculiar at all. Since Mosquitto v2, you must explicitly set allow_anonymous true:

https://github.com/chirpstack/chirpstack-docker/blob/master/configuration/mosquitto/mosquitto.conf

Could it be that this configuration was not (correctly) loaded?

curio77 commented 1 year ago

I'm aware of that change (I use Mosquitto in quite a lot of contexts) and did check MQTT communications via (anonymous) mosquitto_{pub,sub} in the course of looking for the cause of the ChirpStack issue.

Still, the ChirpStack error reoccurred until that switch down to Mosquitto v1.6 and back up. I have no idea what else that may have changed that may have had that resolving effect. The Mosquitto config file at least has not changed.