0

How can I tell Network Manager to keep trying to reconnect to a wifi network forever?

I'm trying to use the Internet at a public wifi access point that I cannot control. I don't know why, but the network is not very good. Once I'm connected, it works decently for several hours. But it takes between several dozen to several hundred connection attempts before it will finally connect.

NetworkManager[565]: <info>  [1705593163.7081] device (wls6f0): Activation: starting connection 'MA:CA:DD:RE:SS_OBFUSCATED' (uuid_obfuscated)
...
NetworkManager[565]: <info>  [1705593186.8841] manager: NetworkManager state is now CONNECTING
...
NetworkManager[565]: <info>  [1705593186.8968] device (wls6f0): Activation: (wifi) connection 'SSID_OBFUSCATED 1' has security, and secrets exist.  No new secrets needed.
...
NetworkManager[565]: <info>  [1705593186.9172] device (wls6f0): supplicant interface state: disconnected -> scanning
NetworkManager[565]: <info>  [1705593186.9175] device (p2p-dev-wls6f0): supplicant management interface state: disconnected -> scanning
NetworkManager[565]: <info>  [1705593188.0184] device (wls6f0): supplicant interface state: scanning -> authenticating
NetworkManager[565]: <info>  [1705593188.0187] device (p2p-dev-wls6f0): supplicant management interface state: scanning -> authenticating
NetworkManager[565]: <info>  [1705593191.0121] device (wls6f0): supplicant interface state: authenticating -> disconnected
NetworkManager[565]: <info>  [1705593191.0122] device (p2p-dev-wls6f0): supplicant management interface state: authenticating -> disconnected
NetworkManager[565]: <info>  [1705593201.0140] device (wls6f0): supplicant interface state: disconnected -> scanning
NetworkManager[565]: <info>  [1705593201.0144] device (p2p-dev-wls6f0): supplicant management interface state: disconnected -> scanning
NetworkManager[565]: <info>  [1705593201.0592] device (wls6f0): supplicant interface state: scanning -> authenticating
NetworkManager[565]: <info>  [1705593201.0594] device (p2p-dev-wls6f0): supplicant management interface state: scanning -> authenticating
NetworkManager[565]: <info>  [1705593204.0095] device (wls6f0): supplicant interface state: authenticating -> disconnected
NetworkManager[565]: <info>  [1705593204.0098] device (p2p-dev-wls6f0): supplicant management interface state: authenticating -> disconnected
NetworkManager[565]: <warn>  [1705593212.1450] device (wls6f0): Activation: (wifi) association took too long, failing activation

Unfortunately, after failing to connect, NetworkManager stops trying. This is ridiculous because I have to sit at my computer waiting for it to timeout and then click the icon and select the SSID manually. Over-and-over. I had to do this for an hour this morning. Aren't computers supposed to automate things? I've just turned myself into a tap bot.

What I want is to be able to say "connect to this" and walk away and make lunch, knowing that NetworkManager will attempt to connect over-and-over until [a] it connects or [b] the end of time comes. I should be able to step away from the computer to make lunch and be sure that after I return, it will be connected (currently when I tell it to connect, I come back to my computer and realize that NetworkManager is sitting idle, having "given up".

How can I automate this process by telling NetworkManager to try to connect to the same wifi network over-and-over (forever) until it finally connects?

1 Answer 1

1

I don't know how to configure Network Manager to be less lazy and keep trying, but I do know how to write a script that watches Network Manager and forces it to keep working.

#!/bin/bash
set -x

IF_DEV="wls6f0"

while true; do
    date
    state=$(nmcli device status | grep "${IF_DEV} " | head -n1 | awk '{print $3}')
    if [[ "$state" == "disconnected" ]]; then
        echo "INFO: Caught NM sitting idle. Forcing it to try to reconnect again!";
        sudo nmcli device connect "${IF_DEV}"
    fi
    sleep 1;
    echo;
done

The above script is a simple hack that, when run, will check to see if the interface device (set in $IF_DEV) is connected or not.

If its state is disconnected, it will tell Network Manager to try to connect (which will default to attempting to connect to previously-connected networks).

Otherwise (eg if it's in the state connecting or connected), it will wait 1 second and then check again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .