On Mon, 2021-03-01 at 10:54 -0500, Steve Newcomb wrote:
> I have 2 hosts that experience interruptions in their
> NetworkManager-managed wifi connections.
>
> In an attempt to force the hosts to restore their wifi connections
> more promptly than they otherwise would, I have them running a cron
> job called "keepWirelessAlive.py" every 3 minutes. If wifi is
> running, the job does nothing. If not, it attempts to restore the
> connection using nmcli:
>
> nmcli device connect wlp3s0
`man nmcli` says about `nmcli device connect`:
Connect the device. NetworkManager will try to find a suitable
connection that will be activated. It will also consider
connections that are not set to auto connect.
If no compatible connection exists, a new profile with default
settings will be created and activated. This differentiates nmcli
connection up ifname "$DEVICE" from nmcli device connect "$DEVICE"
The case where nmcli finds a suitable existing profile and connects it
is clear. But if the SSID for that profile is not in range, no suitable
profile is found and NetworkManager is told to create a new profile.
`nmcli device connect` does that by providing an incomplete profile,
that NetworkManager completes. However, `nmcli device connect` does not
work in that case, because you would at least need to specify the SSID.
Thus, creating a profile with `nmcli device connect` does not work.
Instead, it would work with `nmcli device connect wifi ssid ...`.
It sounds like you don't want to use `nmcli device connect`. Use `nmcli
connection up "$PROFILE"` or even `nmcli connection profile "$PROFIILE"
ifname "$IFACE"`.
If you really don't want to select the profile yourself, and let
NetworkManager choose one, maybe you need to first ensure that the Wi-
Fi scan list is up to date. That is, issue a `nmcli device wifi rescan`
before `nmcli device connect`.
But anyway, sometimes connecting to a Wi-Fi may fail. For example, when
the SSID cannot be found. It may simply happen sometimes. Ignore the
error and retry after a while.
If you want to understand why any of that happens, enable level=TRACE
log ([1]) in NetworkManager and debug logging for supplicant.
[1]
https://cgit.freedesktop.org/NetworkManager/NetworkManager/tree/contrib/fedora/rpm/NetworkManager.conf#n28
Also, I would try to solve those interruptions, instead of adding a
cron job like this... again, the (trace/debug) logfile is the way to
go.
best,
Thomas
>
> (see below). The command works fine in tests, but when such an attempt
> is made automatically by the cron job, it fails, and NetworkManager's
> log
> messages explain that I've failed to specify a 'wireless' setting (see
> below). Alas, I can't find a 'wireless' setting anywhere in
> NetworkManager's documentation, so I suspect the log message could be
> clearer.
>
> Everything is OK:
>
> Mar 1 00:18:01 carp CRON[2615]: (root) CMD
> (/usr/local/ch-tools3/keepWirelessAlive.py)
> Mar 1 00:21:01 carp CRON[2740]: (root) CMD
> (/usr/local/ch-tools3/keepWirelessAlive.py)
>
> But then the connection is lost:
>
> Mar 1 00:23:36 carp NetworkManager[657]: [1614576216.8719]
> sup-iface[0x557adf36a8d0,wlp3s0]: connection disconnected (reason -4)
> Mar 1 00:23:36 carp NetworkManager[657]: [1614576216.8993]
> device (wlp3s0): supplicant interface state: completed -> disconnected
> Mar 1 00:23:36 carp NetworkManager[657]: [1614576216.9775]
> device (wlp3s0): supplicant interface state: disconnected -> scanning
> Mar 1 00:23:40 carp NetworkManager[657]: [1614576220.2651]
> device (wlp3s0): supplicant interface state: scanning -> authenticating
> Mar 1 00:23:40 carp NetworkManager[657]: [1614576220.3809]
> device (wlp3s0): supplicant interface state: authenticating ->
> disconnected
> Mar 1 00:23:40 carp NetworkManager[657]: [1614576220.8807]
> device (wlp3s0): supplicant interface state: disconnected -> scanning
> Mar 1 00:23:52 carp NetworkManager[657]: [1614576232.5545]
> device (wlp3s0): link timed out.
> Mar 1 00:23:52 carp NetworkManager[657]: [1614576232.5567]
> device (wlp3s0): state change: activated -> failed (reason
> 'ssid-not-found', sys-iface-state: 'managed')
> Mar 1 00:23:52 carp NetworkManager[657]: [1614576232.5667]
> manager: NetworkManager state is now DISCONNECTED
> Mar 1 00:23:53 carp NetworkManager[657]: [1614576233.5961]
> device (wlp3s0): Activation: failed for connection 'X'
> Mar 1 00:23:53 carp NetworkManager[657]: [1614576233.5997]
> device (wlp3s0): state change: failed -> disconnected (reason 'none',
> sys-iface-state: 'managed')
> Mar 1 00:23:53 carp dbus-daemon[655]: [system] Activating via systemd:
> service name='org.freedesktop.nm_dispatcher'
> unit='dbus-org.freedesktop.nm-dispatcher.service' requested by ':1.13'
> (uid=0 pid=657 comm="/usr/sbin/NetworkManager --no-daemon ")
> Mar 1 00:23:53 carp NetworkManager[657]: [1614576233.6407]
> dhcp4
> (wlp3s0):