yllibed / Zigbee2MqttAssistant

GUI for Zigbee2Mqtt running in docker and HASS.IO
449 stars 42 forks source link

Unable to connect to MQTT server #187

Closed wisekki closed 4 years ago

wisekki commented 4 years ago

Just installed the Zigbee2MqttAssistant as hassio add-on and configured the credentials but the log says:

Starting Zigbee2MqttAssistant v0.3.140+Branch.master.Sha.38110698516fbf4b56dd7b8de4a4def0f6bf70c1... Hosting environment: Production Content root path: /app Now listening on: http://[::]:80 Application started. Press Ctrl+C to shut down. warn: Zigbee2MqttAssistant.Services.MqttConnectionService[0] Unable to connect to MQTT server 192.168.1.1:1883. MQTTnet.Exceptions.MqttCommunicationException: Name does not resolve ---> System.Net.Internals.SocketExceptionFactory+ExtendedSocketException (00000005, 0xFFFDFFFF): Name does not resolve at System.Net.Dns.InternalGetHostByName(String hostName) at System.Net.Dns.ResolveCallback(Object context) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source) at System.Net.Dns.HostResolutionEndHelper(IAsyncResult asyncResult) at System.Net.Dns.EndGetHostAddresses(IAsyncResult asyncResult) at System.Net.Sockets.Socket.DoDnsCallback(IAsyncResult result, MultipleAddressConnectAsyncResult context) at System.Net.Sockets.Socket.DnsCallback(IAsyncResult result) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw(Exception source) at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult) at System.Net.Sockets.Socket.<>c.b__277_0(IAsyncResult iar) --- End of stack trace from previous location where exception was thrown --- at MQTTnet.Implementations.MqttTcpChannel.ConnectAsync(CancellationToken cancellationToken) at MQTTnet.Internal.MqttTaskTimeout.WaitAsync(Func`2 action, TimeSpan timeout, CancellationToken cancellationToken) at MQTTnet.Adapter.MqttChannelAdapter.ConnectAsync(TimeSpan timeout, CancellationToken cancellationToken) --- End of inner exception stack trace --- at MQTTnet.Adapter.MqttChannelAdapter.WrapException(Exception exception) at MQTTnet.Adapter.MqttChannelAdapter.ConnectAsync(TimeSpan timeout, CancellationToken cancellationToken) at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken) at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken) at MQTTnet.Extensions.ManagedClient.ManagedMqttClient.ReconnectIfRequiredAsync()

I'm running mqtt server at 192.168.1.1:1883 but for some reason the Zigbee2MqttAssistant docker is unable to access that address. I've tried the configuration with and without the port number. Also localhost or any other name pointed to that address does not work.

carldebilly commented 4 years ago

Looks like you put the port in the server name setting. The port is a different setting.

wisekki commented 4 years ago

Okay well it does not work only with 192.168.1.1 or localhost (or firewall that is on my hosts). Does it require port number by default?

wisekki commented 4 years ago

from the Zigbee2MqttAssistant docker I can ping 192.168.1.1 so it works.

carldebilly commented 4 years ago

Is your MQTT broker installed on the same docker? If yes, you should just put the name of the other container :-).

wisekki commented 4 years ago

Nope.. mqtt is not on a docker.. it's running directly on 192.168.1.1 :)

maartenhd commented 4 years ago

Same problem ; Application started. Press Ctrl+C to shut down. warn: Zigbee2MqttAssistant.Services.MqttConnectionService[0] Unable to connect to MQTT server mqtt://192.168.2.16. MQTTnet.Exceptions.MqttCommunicationException: Name does not resolve

carldebilly commented 4 years ago

You should read the doc... don't put the mqtt:// at the beginning of the broker address.

wisekki commented 4 years ago

At the moment it does not matter what we (at least me) put on the broker address.. Everything says "Unable to connect" and i've tried every combination i can think of.. :( And mqtt broker works from other dockers.

marcgarciamarti commented 4 years ago

Same here. Whatever I try as mqtt ip address, does not seem to work. I'm running hassio (now called home assistant) 0.105.1 and the officail mosquitto add-on. I just tried now 172.30.33.0 because I'm running out of options but it did not work either

~ $ nslookup core-mosquitto
Server:     127.0.0.11
Address:    127.0.0.11#53

Non-authoritative answer:
Name:   core-mosquitto
Address: 172.30.33.0
Starting Zigbee2MqttAssistant v0.3.133+Branch.master.Sha.f490bd70a0401bc6d96a4d02d5f9022a43bb5e9e...
Hosting environment: Production
Content root path: /app
Now listening on: http://[::]:80
Application started. Press Ctrl+C to shut down.
warn: Zigbee2MqttAssistant.Services.MqttConnectionService[0]
      Unable to connect to MQTT server 172.30.33.0.

any help would be most appreciated.

thanks

mvivaldi commented 4 years ago

Same problem here, zigbee2mqttassistant running in docker and external (not in docker) mqtt server (mosquitto).

Application started. Press Ctrl+C to shut down.
warn: Zigbee2MqttAssistant.Services.MqttConnectionService[0]
      Unable to connect to MQTT server 192.168.1.105.
MQTTnet.Exceptions.MqttCommunicationException: Connection reset by peer
 ---> System.Net.Sockets.SocketException (104): Connection reset by peer
   --- End of inner exception stack trace ---
   at MQTTnet.Adapter.MqttChannelAdapter.WrapException(Exception exception)
   at MQTTnet.Adapter.MqttChannelAdapter.ConnectAsync(TimeSpan timeout, CancellationToken cancellationToken)
   at MQTTnet.Client.MqttClient.ConnectAsync(IMqttClientOptions options, CancellationToken cancellationToken)

And on 192.168.1.105 with tcpdump there is no attempt to connect

mvivaldi commented 4 years ago

Ok I found the problem in my configuration: I needed to set Z2MA_SETTINGS__MQTTSECURE=false (to use mqtt on port 1883), after this change of configuration everything works

marcgarciamarti commented 4 years ago

Ok I found the problem in my configuration: I needed to set Z2MA_SETTINGS__MQTTSECURE=false (to use mqtt on port 1883), after this change of configuration everything works

@mvivaldi you got me. What is that? I see in the documentation a reference to environmental variables. I have no idea what that is about. Could you explain?

wisekki commented 4 years ago

I'm using this as hass.io addon and when I added "mqttsecure: false" to the config it didn't help. (Maybe it's some other param?) Still I get:

warn: Zigbee2MqttAssistant.Services.MqttConnectionService[0] Unable to connect to MQTT server 192.168.1.1. MQTTnet.Exceptions.MqttCommunicationException: Cannot access a disposed object.

mvivaldi commented 4 years ago

I set the port and the mqttsecure parameter in my docker compose file:

version: '3'                                                                                                                                                                                                                                                                                                                                                              
services:  
  zigbee2mqttAssistant:
    image: carldebilly/zigbee2mqttassistant:dev
    container_name: zigbee2mqttAssistant
    environment:
      - Z2MA_SETTINGS__MQTTSERVER=mymqttserver
      - Z2MA_SETTINGS__MQTTUSERNAME=myusername
      - Z2MA_SETTINGS__MQTTPASSWORD=mypassword
      - Z2MA_SETTINGS__MQTTPORT=1883
      - Z2MA_SETTINGS__MQTTSECURE=false
      # Set to your TimeZone when using on Linux https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
      # Won't work if you're using the Windows version of the container
      - TZ=Europe/Rome
    ports:
      - 8880:80
    restart: unless-stopped
marcgarciamarti commented 4 years ago

I set the port and the mqttsecure parameter in my docker compose file:

version: '3'                                                                                                                                                                                                                                                                                                                                                              
services:  
  zigbee2mqttAssistant:
    image: carldebilly/zigbee2mqttassistant:dev
    container_name: zigbee2mqttAssistant
    environment:
      - Z2MA_SETTINGS__MQTTSERVER=mymqttserver
      - Z2MA_SETTINGS__MQTTUSERNAME=myusername
      - Z2MA_SETTINGS__MQTTPASSWORD=mypassword
      - Z2MA_SETTINGS__MQTTPORT=1883
      - Z2MA_SETTINGS__MQTTSECURE=false
      # Set to your TimeZone when using on Linux https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
      # Won't work if you're using the Windows version of the container
      - TZ=Europe/Rome
    ports:
      - 8880:80
    restart: unless-stopped

Mmm this does not sound much like hassio, does it?

mvivaldi commented 4 years ago

sorry for the late reply, in my case is not hassio, but a simple docker container.

magpern commented 4 years ago

From previous issues I can concluded that all are up and running for now. Closing this and referring to #216 at the moment

timdonovanuk commented 4 years ago

This just causes an exception for me:

Unhandled exception. System.InvalidOperationException: Failed to convert configuration value at 'settings:MqttSecure' to type 'Zigbee2MqttAssistant.Models.TlsMode'.

timdonovanuk commented 4 years ago

Also Unhandled exception. System.InvalidOperationException: Failed to convert configuration value at 'settings:MqttPort' to type 'System.UInt16'.

timdonovanuk commented 4 years ago

My goodness, adding " around the parameters such as:

- Z2MA_SETTINGS__MQTTSERVER="192.168.1.4"

seems to cause this entire connection problem!