WLAN Verbindung angepasst
This commit is contained in:
@@ -15,7 +15,7 @@ Die Software liegt in diesem Repository direkt an der Wurzel. Nicht zur Software
|
||||
| **Benutzer** | `pi` |
|
||||
| **SSH-Passwort** | `Sonneberg` |
|
||||
| **LAN-IP** | `192.168.1.83` |
|
||||
| **WLAN-IP** | `192.168.1.9` (bevorzugt) |
|
||||
| **WLAN-IP** | `192.168.1.9` |
|
||||
| **Fallback-AP** | SSID `CUNO`, IP `192.168.50.1`, Passwort `astr0cun042` |
|
||||
|
||||
```bash
|
||||
@@ -49,7 +49,17 @@ f710_joy_node ──────────────────────
|
||||
|---|---|
|
||||
| `exomy-admin-api.service` | Admin-API (`exomy_admin_api.py`) |
|
||||
| `exomy-camera-stream.service` | MJPEG Kamera-Stream |
|
||||
| `exomy-wifi-fallback.service` | WLAN-Fallback auf eigenen Access Point |
|
||||
| `exomy-wifi-bootstrap.service` | Wählt beim Start `4pi` oder `eskimue.de`, sonst eigener Access Point |
|
||||
|
||||
### WLAN-Startlogik
|
||||
|
||||
Beim Booten sucht der Rover genau einmal nach den bekannten WLANs `4pi` und `eskimue.de`.
|
||||
|
||||
- Wenn `4pi` sichtbar ist, verbindet er sich mit `4pi`.
|
||||
- Sonst, wenn `eskimue.de` sichtbar ist, verbindet er sich mit `eskimue.de`.
|
||||
- Wenn keines von beiden sichtbar ist, spannt er den eigenen Access Point `CUNO` auf.
|
||||
|
||||
Nach dieser Entscheidung bleibt die gewählte Verbindung bestehen. Es gibt kein späteres Nachscannen und kein automatisches Umschalten auf ein anderes WLAN oder auf den Access Point. Erst nach einem Neustart wird erneut gesucht.
|
||||
|
||||
```bash
|
||||
# Status prüfen
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user