Wifi does not reconnect if router was gone

Hello,

I found several topics with similar issues, but they were not that helpful (restart HA, use wired connection, buy a new router, get better signal, ping google and restart HA with an automation).

My HAOS Pi4 uses two network interfaces, wired and wifi, and both are active to connect devices in different networks. The wifi interface has a static ip, WPA2, etc. Usually every thing works fine.

But sometimes when the wifi router was not available (due to whatever reasons) the wlan is not reconnecting once it is available again.

SSHing into the system, over wired, of course :slight_smile: shows

nmcli
wlan0: disconnected

nmcli c
Wired connection 1  ...   ethernet  eth0   
my-network          ...    wifi      --

If I just type

nmcli c up my-network

at that point the wifi reconnects and everything is fine.

Any ideas why it does not reconnect on its own?

You could automate that.

Yes, as I mentioned in the first post, I know that :slight_smile:
But that does not really solve the issue it for me.
I am wondering why the connection stays down if it was down.

Is there some setting so a reconnect is not triggered if there is a second connection that is alive?

I really don’t know sorry.

Rather odd to use 2 network interfaces on home assistant. I am not sure that home assistant OS will be optimised for that.

If you are not using HAOS it is a question for your OS forum rather than here.

I think I found a possible solution. There is indeed a setting for autoconnect:

nmcli connection show my-network

returns

connection.autoconnect:                 yes
connection.autoconnect-priority:        0
connection.autoconnect-retries:         -1 (default)

So, autoconnect is enabled by default, BUT what is the default for autoconnect-retries? :slight_smile:

The nmcli docs state:

The number of times a connection should be tried when autoactivating before giving up. Zero means forever, -1 means the global default (4 times if not overridden).

Four? Why four? Why not 42? What kind of default is that supposed to be?
Kind of “Please try, but not that hard.” :slight_smile:

The command to set it to forever is

nmcli connection modify my-network connection.autoconnect-retries 0

nmcli connection show my-network
> connection.autoconnect-retries: 0 (forever)

You can also modify the parameter using the “my-network” file on SD or USB:

[connection]
...
type=wifi
autoconnect=1
autoconnect-retries=0

Also be sure to check the NetworkManager logs to identify reasons for the connection loss, e.g. if the router kicks you out or whatever:

journalctl -u NetworkManager -n 100 --no-pager

I saw that
cat /etc/NetworkManager/NetworkManager.conf

also shows an entry

[main]
autoconnect-retries-default=0

but that did not apply to the connections (but not sure if it should).

5 Likes

This post should be stickied :slight_smile: thank you so much!

On latest version of HAOS with default settings my network command was:

nmcli connection modify "Supervisor wlan0" connection.autoconnect-retries 0
1 Like

nmcli connection modify “Supervisor wlan0” connection.autoconnect-retries 0

This gives me:

I also tried this command, but it gives an error.

Any advice?