tsujamin / hass-addons

108 stars 35 forks source link

Not able to receive MQTT messages #74

Closed ChrisKolan closed 1 year ago

ChrisKolan commented 1 year ago

I have two machines on the Tailscale network. One of them has a home assistant set up with Mosquitto broker. I am unable to send messages to the broker. The sending machine confirms the connection to the broker and the sending of the message, but the message never arrives. I have tried many settings, however, none work. After sending the message I see the following log on home assistant machine:

2023/03/26 18:29:56 portmapper: failed to get PCP mapping: PCP is implemented but not enabled in the router 2023/03/26 18:29:57 portmapper: failed to get PCP mapping: PCP is implemented but not enabled in the router 2023/03/26 18:29:57 Accept: TCP{100.103.124.23:39321 > 100.72.7.95:1883} 60 tcp ok 2023/03/26 18:29:57 Accept: TCP{100.103.124.23:39321 > 100.72.7.95:1883} 52 tcp non-syn 2023/03/26 18:29:57 Accept: TCP{100.103.124.23:39321 > 100.72.7.95:1883} 95 tcp non-syn

Port: 1883 is the default MQTT port.

My current setup is as follows:

hostname: homeassistant
userspace_networking: true
auth_key: tskey-xxx
accept_routes: true
ssh: false
disable_dns: false
advertise_exit_node: false
reset: true
tsujamin commented 1 year ago

Hey there

Sorry you're having this issue. What I think could be happening is that when you connect to the MQTT broker (100.72.7.95:1883) you're actually conencting to 1883 within the Tailscale daemon on the remote end, not connecting through to the MQTT service in (I presume) another container.

Something you could try is:

  1. On the MQTT-hosting instance, advertise its local IP address (not the tailscale one) as a subnet route in the Tailscale addon
  2. On the MQTT client side, instruct Tailscale to accept routes
  3. On the MQTT client side, instruct MQTT to connect to the newly advertised local IP

Not sure if this will work, all the containers and userspace/non-userspace networking gets a bit messy :( let me know how you go!

Alternatively you could play with disabling userspace networking on the MQTT server side and enabling the SNAT option, but yeah that will have other impacts...

ChrisKolan commented 1 year ago

Hi @tsujamin thanks for the tips. I tried to follow the instructions as you described. On the MQTT client side I am able to ping the MQTT-hosting instance using the local IP. I am also able to send an MQTT message (without any errors) to the local IP of the MQTT-host, however the message does not reach the host...

My config:

hostname: homeassistant
userspace_networking: false
auth_key: tskey-auth-xxx
accept_routes: true
ssh: false
disable_dns: false
advertise_exit_node: false
reset: false
advertise_routes: 192.168.178.0/24

With these settings, I can't see in the logs at all that any connection has taken place.