Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stuck in "Attempting to reconnect MQTT Broker..." loop #61

Closed
fender4645 opened this issue Feb 29, 2020 · 2 comments
Closed

Stuck in "Attempting to reconnect MQTT Broker..." loop #61

fender4645 opened this issue Feb 29, 2020 · 2 comments

Comments

@fender4645
Copy link

I'm setting up ring-mqtt for the first time with my HA install. Everything runs inside their own Docker container. For the MQTT Broker, I'm using the "eclipse-mosquitto" docker image and configured it with a user/password. I tested by running the following commands:

mosquitto_sub -h localhost -t "test" -u "<username>" -P "<password>"
mosquitto_pub -h localhost -t "test" -m "Hello World" -u "<username>" -P "<password>"

The client was able to receive the "Hello World" message just fine.

I followed the instructions for setting up the "ring-mqtt" docker image and got it up and running. After adding the mqtt component to HA and restarting, I didn't see any of my Ring alarm sensors. I added the DEBUG option, started the "ring-mqtt" container, and then ran "docker-compse logs
ring-mqtt" and saw that the script was attempting to reconnect to the broker every second:

ring-mqtt            | 2020-02-29T07:30:11.716Z ring-mqtt Configuration file read from: ./config
ring-mqtt            | 2020-02-29T07:30:11.717Z ring-mqtt Configuration file not found, try environment variables!
ring-mqtt            | 2020-02-29T07:30:13.293Z ring-mqtt Connection to Ring API successful
ring-mqtt            | 2020-02-29T07:30:13.293Z ring-mqtt Starting connection to MQTT broker...
ring-mqtt            | 2020-02-29T07:30:14.400Z ring-mqtt Attempting to reconnect to MQTT broker...
ring-mqtt            | 2020-02-29T07:30:15.404Z ring-mqtt Attempting to reconnect to MQTT broker...
ring-mqtt            | 2020-02-29T07:30:16.407Z ring-mqtt Attempting to reconnect to MQTT broker...
ring-mqtt            | 2020-02-29T07:30:17.411Z ring-mqtt Attempting to reconnect to MQTT broker...
ring-mqtt            | 2020-02-29T07:30:18.414Z ring-mqtt Attempting to reconnect to MQTT broker...
ring-mqtt            | 2020-02-29T07:30:19.417Z ring-mqtt Attempting to reconnect to MQTT broker...
ring-mqtt            | 2020-02-29T07:30:20.420Z ring-mqtt Attempting to reconnect to MQTT broker...
ring-mqtt            | 2020-02-29T07:30:21.422Z ring-mqtt Attempting to reconnect to MQTT broker...
ring-mqtt            | 2020-02-29T07:30:22.424Z ring-mqtt Attempting to reconnect to MQTT broker...
ring-mqtt            | 2020-02-29T07:32:15.373Z ring-mqtt Exit code: SIGTERM
ring-mqtt            | 2020-02-29T07:32:15.728Z ring-mqtt Attempting to reconnect to MQTT broker...
ring-mqtt            | 2020-02-29T07:32:16.374Z ring-mqtt Exit code: 0

The last line is me stopping the container. Here is my docker compose entry:

ring-mqtt:
  image: tsightler/ring-mqtt
  container_name: ring-mqtt
  environment:
    - DEBUG=ring-mqtt
    - PUID=1000
    - GUID=1000
    - TZ=America/Los_Angeles
    - MQTTHOST=localhost
    - MQTTPORT=1883
    - MQTTRINGTOPIC=ring
    - MQTTHASSTOPIC=hass/status
    - MQTTUSER=<mqtt username>
    - MQTTPASSWORD=<mqtt password>
    - RINGTOKEN=<ring token>

Any ideas on what's going on? Thanks!

@tsightler
Copy link
Owner

The most likely issue is the attempted use of MQTTHOST=localhost when you're running both mosquitto and ring-mqtt in separate containers. If you are not using host network mode within Docker then you can't just use "localhost" to connect between Docker containers. With the current setup effectively ring-mqtt is attempting to connect to an MQTT broker within it's own container.

So you'll either need to change to using the IP address/hostname of the docker host itself instead of using localhost, or you'll need to add the appropriate "network_mode" to your docker compose. At least that's my guess based on what you've provided to this point.

@fender4645
Copy link
Author

Good catch! I had originally setup the container in network_mode = "host" but removed when I realized it didn't need any incoming networking. Changing MQTTHOST to the IP worked. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants