WLAN Verbindung angepasst

This commit is contained in:
2026-05-28 08:00:56 +02:00
parent cb33bbf06c
commit a42b87507b
6 changed files with 103 additions and 64 deletions
+12
View File
@@ -0,0 +1,12 @@
[Unit]
Description=ExoMy WLAN Startauswahl
After=NetworkManager.service
Wants=NetworkManager.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/exomy-wifi-bootstrap-manager.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
-13
View File
@@ -1,13 +0,0 @@
[Unit]
Description=ExoMy WLAN Fallback Manager
After=NetworkManager.service
Wants=NetworkManager.service
[Service]
Type=simple
ExecStart=/usr/local/bin/exomy-wifi-fallback-manager.sh
Restart=always
RestartSec=5
[Install]
WantedBy=multi-user.target
+7
View File
@@ -222,6 +222,13 @@ def get_wifi_status():
device, state, connection = parts
if device == 'wlan0':
if state == 'connected':
ssid_stdout, _, ssid_returncode = run_command(['nmcli', '-t', '-f', 'ACTIVE,SSID', 'device', 'wifi', 'list', 'ifname', 'wlan0'])
if ssid_returncode == 0 and ssid_stdout:
for ssid_line in ssid_stdout.splitlines():
if ssid_line.startswith('yes:'):
active_ssid = ssid_line.split(':', 1)[1].strip()
if active_ssid:
return f'verbunden: {active_ssid}'
return f'verbunden: {connection}'
return state
+72
View File
@@ -0,0 +1,72 @@
#!/bin/bash
set -euo pipefail
WIFI_IFACE="wlan0"
KNOWN_CONNECTIONS=(
"4pi:4pi"
"eskimue.de:netplan-wlan0-eskimue.de"
)
FALLBACK_AP_CONN="CUNO-AP"
SCAN_WAIT_SECONDS=10
get_active_connection() {
nmcli -t -f GENERAL.CONNECTION device show "$WIFI_IFACE" 2>/dev/null | head -n 1 | cut -d: -f2-
}
activate_connection() {
local connection_name="$1"
nmcli --wait 15 connection up "$connection_name" ifname "$WIFI_IFACE" >/dev/null 2>&1
}
is_known_connection() {
local active_connection="$1"
local entry
for entry in "${KNOWN_CONNECTIONS[@]}"; do
local connection_name="${entry#*:}"
if [[ "$active_connection" == "$connection_name" ]]; then
return 0
fi
done
return 1
}
scan_for_known_connection() {
local visible_ssids
local entry
nmcli device wifi rescan ifname "$WIFI_IFACE" >/dev/null 2>&1 || true
sleep "$SCAN_WAIT_SECONDS"
visible_ssids="$(nmcli -t -f SSID device wifi list ifname "$WIFI_IFACE" 2>/dev/null || true)"
for entry in "${KNOWN_CONNECTIONS[@]}"; do
local ssid="${entry%%:*}"
local connection_name="${entry#*:}"
if printf '%s\n' "$visible_ssids" | grep -Fxq "$ssid"; then
echo "$connection_name"
return 0
fi
done
return 1
}
activate_initial_connection() {
local active_connection
local selected_connection
active_connection="$(get_active_connection)"
if is_known_connection "$active_connection"; then
return 0
fi
if selected_connection="$(scan_for_known_connection)"; then
activate_connection "$selected_connection"
return 0
fi
activate_connection "$FALLBACK_AP_CONN" || true
}
activate_initial_connection
-49
View File
@@ -1,49 +0,0 @@
#!/bin/bash
set -euo pipefail
WIFI_IFACE="wlan0"
PRIMARY_CONN="netplan-wlan0-eskimue.de"
SECONDARY_CONN="4pi"
FALLBACK_AP_CONN="CUNO-AP"
CHECK_INTERVAL=20
get_active_connection() {
nmcli -t -f GENERAL.CONNECTION device show "$WIFI_IFACE" 2>/dev/null | head -n 1 | cut -d: -f2-
}
activate_connection() {
local connection_name="$1"
nmcli --wait 15 connection up "$connection_name" ifname "$WIFI_IFACE" >/dev/null 2>&1
}
ensure_best_connection() {
local active_connection
active_connection="$(get_active_connection)"
if [[ "$active_connection" == "$PRIMARY_CONN" ]]; then
return
fi
if activate_connection "$PRIMARY_CONN"; then
return
fi
active_connection="$(get_active_connection)"
if [[ "$active_connection" == "$SECONDARY_CONN" ]]; then
return
fi
if activate_connection "$SECONDARY_CONN"; then
return
fi
active_connection="$(get_active_connection)"
if [[ "$active_connection" != "$FALLBACK_AP_CONN" ]]; then
activate_connection "$FALLBACK_AP_CONN" || true
fi
}
while true; do
ensure_best_connection
sleep "$CHECK_INTERVAL"
done