いくつかの外部ロジックに基づいて、IoTデバイスが接続されているAPを切り替えたいと思います。私のAP移行スクリプトは次のとおりです。
function switch_ap() {
current_connection=$(nmcli conn show --active | tail -n 1 | cut -d' ' -f1)
nmcli conn down $current_connection
if test "$current_connection" = "home_ap"; then
nmcli conn up iot_ap
else
nmcli conn up home_ap
fi
new_connection=$(nmcli conn show --active | tail -n 1 | cut -d' ' -f1)
echo "was connected to $current_connection, now connected to connection: $(nmcli conn show --active | tail -n 1 | cut -d' ' -f1) ssid: $(iwgetid wlan0 -r)"
}
これは時々動作しますが、信頼できません。多くの場合、エラーが発生します。
Connection 'home_ap' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/66)
Error: Connection activation failed: The base network connection was interrupted
Hint: use 'journalctl -xe NM_CONNECTION=dcbf7f18-1e26-41bb-a874-c1ce6718dbf2 + NM_DEVICE=wlan0' to get more details.
コマンドの実行に問題はありませんが、journalctl
他の人がこのログをよりよく解析できるように、この投稿の一番下に出力を共有します。
私のハッキング修正は次の機能です。
function switch_ap() {
current_connection=$(nmcli conn show --active | tail -n 1 | cut -d' ' -f1)
nmcli conn down $current_connection
if test "$current_connection" = "home_ap"; then
mv /etc/nm_connections/iot_ap.nmconnection /opt/nm_connections/
mv /opt/home_ap.nmconnection /etc/nm_connections/
nmcli conn up iot_ap
else
mv /etc/nm_connections/home_ap.nmconnection /opt/nm_connections/
mv /opt/nm_connections/iot_ap.nmconnection /etc/nm_connections/
nmcli conn up home_ap
fi
new_connection=$(nmcli conn show --active | tail -n 1 | cut -d' ' -f1)
echo "was connected to $current_connection, now connected to connection: $(nmcli conn show --active | tail -n 1 | cut -d' ' -f1) ssid: $(iwgetid wlan0 -r)"
}
これは安定して動作するようですが、現在接続されているアプリへの接続が切断されても自動的には切り替わりません。これは一種のハッキングです。また、これらの警告がより頻繁に表示されます。
(process:12734): GLib-GIO-WARNING **: 06:05:20.284: ../../gio/gdbusobjectmanagerclient.c:1589: Processing InterfaceRemoved signal for path /org/freedesktop/NetworkManager/IP4Config/35 but no object proxy exists
(process:12734): GLib-GIO-WARNING **: 06:05:20.293: ../../gio/gdbusobjectmanagerclient.c:1589: Processing InterfaceRemoved signal for path /org/freedesktop/NetworkManager/IP6Config/35 but no object proxy exists
(process:12734): GLib-GIO-WARNING **: 06:05:20.591: ../../gio/gdbusobjectmanagerclient.c:1589: Processing InterfaceRemoved signal for path /org/freedesktop/NetworkManager/ActiveConnection/35 but no object proxy exists
私のAPスイッチングをより安定的にする方法はありますか?
以下はコマンドのログですjournalctl
。
Connection 'iot_ap' successfully deactivated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/33)
Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/37)
Apr 21 09:03:08 DEVICE-072059 NetworkManager[249]: <info> [1587481388.5536] device (wlan0): state change: disconnected -> prepare (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:08 DEVICE-072059 NetworkManager[249]: <info> [1587481388.5912] device (wlan0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:08 DEVICE-072059 NetworkManager[249]: <info> [1587481388.5946] device (wlan0): Activation: (wifi) access point 'home_ap' has security, but secrets are required.
Apr 21 09:03:08 DEVICE-072059 NetworkManager[249]: <info> [1587481388.5948] device (wlan0): state change: config -> need-auth (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:08 DEVICE-072059 NetworkManager[249]: <info> [1587481388.6554] device (wlan0): state change: need-auth -> prepare (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:08 DEVICE-072059 NetworkManager[249]: <info> [1587481388.6598] device (wlan0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:08 DEVICE-072059 NetworkManager[249]: <info> [1587481388.6634] device (wlan0): Activation: (wifi) connection 'home_ap' has security, and secrets exist. No new secrets needed.
Apr 21 09:03:08 DEVICE-072059 NetworkManager[249]: <info> [1587481388.9623] device (wlan0): disconnecting for new activation request.
Apr 21 09:03:08 DEVICE-072059 NetworkManager[249]: <info> [1587481388.9626] device (wlan0): state change: config -> deactivating (reason 'new-activation', sys-iface-state: 'managed')
Apr 21 09:03:08 DEVICE-072059 NetworkManager[249]: <info> [1587481388.9781] device (wlan0): state change: deactivating -> disconnected (reason 'new-activation', sys-iface-state: 'managed')
Apr 21 09:03:09 DEVICE-072059 NetworkManager[249]: <info> [1587481389.0102] device (wlan0): Activation: starting connection 'iot_ap' (b109024a-84b9-46b7-a810-2d2472676c7f)
Apr 21 09:03:09 DEVICE-072059 NetworkManager[249]: <info> [1587481389.0413] device (wlan0): state change: disconnected -> prepare (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:09 DEVICE-072059 NetworkManager[249]: <info> [1587481389.0750] device (wlan0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:09 DEVICE-072059 NetworkManager[249]: <info> [1587481389.0810] device (wlan0): Activation: (wifi) access point 'iot_ap' has security, but secrets are required.
Apr 21 09:03:09 DEVICE-072059 NetworkManager[249]: <info> [1587481389.0819] device (wlan0): state change: config -> need-auth (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:09 DEVICE-072059 NetworkManager[249]: <info> [1587481389.0867] sup-iface[0x3a2201c0,wlan0]: wps: type pbc start...
Apr 21 09:03:09 DEVICE-072059 NetworkManager[249]: <info> [1587481389.8388] device (wlan0): state change: need-auth -> prepare (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:09 DEVICE-072059 NetworkManager[249]: <info> [1587481389.8922] device (wlan0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:09 DEVICE-072059 NetworkManager[249]: <info> [1587481389.9060] device (wlan0): Activation: (wifi) connection 'iot_ap' has security, and secrets exist. No new secrets needed.
Apr 21 09:03:09 DEVICE-072059 NetworkManager[249]: <info> [1587481389.9470] device (wlan0): supplicant interface state: disconnected -> inactive
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.4927] device (wlan0): supplicant interface state: inactive -> associating
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.5582] device (wlan0): disconnecting for new activation request.
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.5584] device (wlan0): state change: config -> deactivating (reason 'new-activation', sys-iface-state: 'managed')
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.5645] device (wlan0): state change: deactivating -> disconnected (reason 'new-activation', sys-iface-state: 'managed')
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.5915] device (wlan0): Activation: starting connection 'home_ap' (dcbf7f18-1e26-41bb-a874-c1ce6718dbf2)
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.6027] device (wlan0): state change: disconnected -> prepare (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.6214] device (wlan0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.6386] device (wlan0): Activation: (wifi) access point 'home_ap' has security, but secrets are required.
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.6388] device (wlan0): state change: config -> need-auth (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <warn> [1587481390.6968] sup-iface[0x3a2201c0,wlan0]: connection disconnected (reason -3)
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.6974] device (wlan0): supplicant interface state: associating -> disconnected
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.6983] device (wlan0): state change: need-auth -> prepare (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.7046] device (wlan0): state change: prepare -> config (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.7357] device (wlan0): Activation: (wifi) connection 'home_ap' has security, and secrets exist. No new secrets needed.
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <info> [1587481390.7815] device (wlan0): supplicant interface state: disconnected -> associated
Apr 21 09:03:10 DEVICE-072059 NetworkManager[249]: <warn> [1587481390.7900] sup-iface[0x3a2201c0,wlan0]: connection disconnected (reason -3)
Apr 21 09:03:11 DEVICE-072059 NetworkManager[249]: <info> [1587481391.0013] device (wlan0): supplicant interface state: associated -> disconnected
Apr 21 09:03:11 DEVICE-072059 NetworkManager[249]: <info> [1587481391.6999] device (wlan0): supplicant interface state: disconnected -> associating
Apr 21 09:03:11 DEVICE-072059 NetworkManager[249]: <info> [1587481391.7886] device (wlan0): supplicant interface state: associating -> 4-way handshake
Apr 21 09:03:11 DEVICE-072059 NetworkManager[249]: <info> [1587481391.8417] device (wlan0): supplicant interface state: 4-way handshake -> completed
Apr 21 09:03:11 DEVICE-072059 NetworkManager[249]: <info> [1587481391.8419] device (wlan0): Activation: (wifi) Stage 2 of 5 (Device Configure) successful. Connected to wireless network "TheHome"
Apr 21 09:03:11 DEVICE-072059 NetworkManager[249]: <info> [1587481391.8624] device (wlan0): state change: config -> ip-config (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:11 DEVICE-072059 NetworkManager[249]: <info> [1587481391.8689] dhcp4 (wlan0): activation: beginning transaction (timeout in 45 seconds)
Apr 21 09:03:11 DEVICE-072059 NetworkManager[249]: <info> [1587481391.8964] dhcp4 (wlan0): dhclient started with pid 22677
Apr 21 09:03:12 DEVICE-072059 NetworkManager[249]: <info> [1587481392.2540] dhcp4 (wlan0): address 192.168.1.61
Apr 21 09:03:12 DEVICE-072059 NetworkManager[249]: <info> [1587481392.2542] dhcp4 (wlan0): plen 24 (255.255.255.0)
Apr 21 09:03:12 DEVICE-072059 NetworkManager[249]: <info> [1587481392.2543] dhcp4 (wlan0): gateway 192.168.1.1
Apr 21 09:03:12 DEVICE-072059 NetworkManager[249]: <info> [1587481392.2546] dhcp4 (wlan0): lease time 10806
Apr 21 09:03:12 DEVICE-072059 NetworkManager[249]: <info> [1587481392.2547] dhcp4 (wlan0): nameserver '75.75.75.75'
Apr 21 09:03:12 DEVICE-072059 NetworkManager[249]: <info> [1587481392.2548] dhcp4 (wlan0): nameserver '75.75.76.76'
Apr 21 09:03:12 DEVICE-072059 NetworkManager[249]: <info> [1587481392.2550] dhcp4 (wlan0): state changed unknown -> bound
Apr 21 09:03:12 DEVICE-072059 NetworkManager[249]: <info> [1587481392.2964] device (wlan0): state change: ip-config -> ip-check (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:12 DEVICE-072059 NetworkManager[249]: <info> [1587481392.3029] device (wlan0): state change: ip-check -> secondaries (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:12 DEVICE-072059 NetworkManager[249]: <info> [1587481392.3051] device (wlan0): state change: secondaries -> activated (reason 'none', sys-iface-state: 'managed')
Apr 21 09:03:12 DEVICE-072059 NetworkManager[249]: <info> [1587481392.4438] device (wlan0): Activation: successful, device activated.
ベストアンサー1
ネットワーク管理者はネットワークを管理するために使用され、可用性に応じてネットワークを切り替えるロジックがあります。最初のスクリプトを実行および削除すると、ネットワーク管理者デーモンが使用可能なデフォルト値を認識して接続できるようになります。
2つ目は、ネットワーク管理者に接続する必要があるWi-Fiアクセスポイントを知らせるファイルを移動することです。したがって、ホームファイルがある場合は、ホームディレクトリにのみ接続できます。これは、ホームディレクトリがホームディレクトリについて知っている唯一のネットワークであるためです。 iotファイルがある場合にのみiotに接続できます。
ネットワーク管理者は、他のネットワークが存在するかどうかわからないため、切り替えられません。問題を解決する最善の方法は、ネットワーク管理者にSSID優先順位を設定するか、電源を切らずに他のSSIDに接続できる「nmcli device wifi connect」を使用することです。このコマンドがない場合は、nmcliのマニュアルページを参照して実行する方法を学びます。