添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
激动的熊猫  ·  Frequent MQTT ...·  1 周前    · 
深情的椅子  ·  My code keeps saying ...·  1 周前    · 
直爽的红烧肉  ·  MQTT 5.0 Packet ...·  1 周前    · 
爱跑步的柳树  ·  MQTT Engine bug - ...·  1 周前    · 
豁达的馒头  ·  Hanns Summer·  8 月前    · 
考研的冰淇淋  ·  CodingStyle/C&C++.md ...·  8 月前    · 
聪明的花生  ·  VS Code Proxy ...·  9 月前    · 

I’m trying to set up an mqtt broker using the official addon, but I keep getting this same error and my ESPHome device cannot connect to it. Logs and steps below:

I downloaded the mqtt broker addon, set up a unique user called mqtt-user, allowed them to log in, local only, and gave them a password. I wnt into integrations and added the mqtt broker, input the username and password, proceeded to the next screen where I left everything default for now, and then attempted to listen to a room (button, for example) and I publish to that same room using the UI and I see the message pop up. When I go to check my ESPHome device, I have provided it with the same username and password via a secrets file, and it continues to pop up the error:

[18:40:04][C][mqtt:030]: Setting up MQTT...
[18:40:04][I][mqtt:175]: Connecting to MQTT...
[18:40:34][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[18:40:34][I][mqtt:175]: Connecting to MQTT...
[18:41:04][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[18:41:04][I][mqtt:175]: Connecting to MQTT...
[18:41:34][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[18:41:34][I][mqtt:175]: Connecting to MQTT...
[18:42:04][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[18:42:04][I][mqtt:175]: Connecting to MQTT...

I check the Home Assistant OS logs and I see the following error pop up every time I restart the mqtt broker addon:

Disconnected from MQTT server core-mosquitto:1883

and the log from the mqtt broker addon itself:

[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] mosquitto.sh: executing... 
[17:20:03] INFO: SSL is not enabled
[cont-init.d] mosquitto.sh: exited 0.
[cont-init.d] nginx.sh: executing... 
[cont-init.d] nginx.sh: exited 0.
[cont-init.d] done.
[services.d] starting services
[17:20:03] INFO: Starting NGINX for authentication handling...
[services.d] done.
[17:20:03] INFO: Starting mosquitto MQTT broker...
1644798003: mosquitto version 1.6.12 starting
1644798003: |-- *** auth-plug: startup
[17:20:03] INFO: Successfully send discovery information to Home Assistant.
[17:20:03] INFO: Successfully send service information to the Supervisor.

This same error happens if I use the host name or if I use the IP address for HA. I’ve checked IP addresses and host names, changed the username and password multiple times and checked via the UI to confirm that I can listen and receive the messages from the test, I’ve uninstalled and reinstalled the addon, deleted the config, nothing is working to resolve this.

Ozymandias:

I wnt into integrations and added the mqtt broker, input the username and password

That might be your issue.

The integration uses a special user (homeassistant). You should not have to specify a username and password for the integration if you are using the Mosquitto addon. With the broker running try removing the mqtt integration, restart home assistant and then try adding the integration again.

https://github.com/home-assistant/addons/blob/89112f96e0db8f207adfb1c988f2d5a26bac9877/mosquitto/DOCS.md#how-to-use

Awesome! Thank you! This removed the HA error but my ESPHome device is still unable to connect. I used the username and password I set up before and the log loops:

[21:06:18][I][mqtt:175]: Connecting to MQTT...
[21:06:49][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[21:06:49][I][mqtt:175]: Connecting to MQTT...
[21:07:18][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[21:07:18][I][mqtt:175]: Connecting to MQTT...
[21:07:48][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[21:07:48][I][mqtt:175]: Connecting to MQTT...
[21:08:19][W][mqtt:260]: MQTT Disconnected: TCP disconnected.

mqtt broker logs show the following:

1644810408: Socket error on client <unknown>, disconnecting.
1644810528: New connection from 172.30.32.2 on port 1883.
1644810528: Socket error on client <unknown>, disconnecting.
1644810554: Saving in-memory database to /data/mosquitto.db.
1644810648: New connection from 172.30.32.2 on port 1883.
1644810648: Socket error on client <unknown>, disconnecting.
1644810768: New connection from 172.30.32.2 on port 1883.
1644810768: Socket error on client <unknown>, disconnecting.
1644810888: New connection from 172.30.32.2 on port 1883.
1644810888: Socket error on client <unknown>, disconnecting.
1644811008: New connection from 172.30.32.2 on port 1883.
1644811008: Socket error on client <unknown>, disconnecting.
  password: !secret wifi_password
  # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "Iotbutton001 Fallback Hotspot"
    password: "<snip>"

And my mqtt config (Options → Addons → mqtt broker → config):

certfile: fullchain.pem
customize:
  active: false
  folder: mosquitto
keyfile: privkey.pem
logins: []
require_certificate: false

I don’t have any usernames or passwords in my mqtt config because I made a Home Assistant user by the name of mqtt-user and the documentation says that all HA users should work automatically. I can log in to a third party app on a different LAN PC using that username and password and IP.

Same issue:

[21:57:51][W][mqtt:260]: MQTT Disconnected: TCP disconnected.
[21:57:51][I][mqtt:175]: Connecting to MQTT...

But I can use mqtt_user and the pass to log in via MQTT Explorer on a different PC on the LAN.

### The problem in my home assistant mosquito add-on, an unknown client no clie

Good catch on the api portion. I have it left out of my other ones but forgot it on this one. I am getting this error now in ESPHome wifi logs:

ERROR Cannot connect to MQTT broker: [Errno 113] No route to host

I moved the mqtt section down to the bottom but maybe I need a longer delay before I call it to allow time to connect to the network?

Not yet but the idea is to wire the button to the reset pin, have the device reboot when the button is pressed, send the mqtt message then go into deep sleep.

I’m not sure why but typing my HA IP in plaintext worked even though my secrets has it correct and all my other ESPHome devices use it!