feat: Fremd-WLAN-Profile löschen und Versionsnummer auf 1.0.74 erhöht
This commit is contained in:
@@ -81,15 +81,14 @@ def stop_ap():
|
|||||||
nm('con', 'down', NM_AP_CON)
|
nm('con', 'down', NM_AP_CON)
|
||||||
|
|
||||||
|
|
||||||
def _takeover_wifi_autoconnect():
|
def _purge_foreign_wifi_profiles():
|
||||||
"""Deaktiviert Autoconnect aller Fremd-WLAN-Profile, damit NM beim Boot PiCopy-WiFi bevorzugt."""
|
"""Löscht alle WLAN-Profile die nicht von PiCopy verwaltet werden (z.B. Imager-Profile)."""
|
||||||
r = nm('-t', '-f', 'NAME,TYPE', 'con', 'show')
|
r = nm('-t', '-f', 'NAME,TYPE', 'con', 'show')
|
||||||
for line in r.stdout.splitlines():
|
for line in r.stdout.splitlines():
|
||||||
parts = line.split(':', 1)
|
parts = line.split(':', 1)
|
||||||
if len(parts) == 2 and parts[1] == '802-11-wireless' and parts[0] not in (NM_CLIENT_CON, NM_AP_CON):
|
if len(parts) == 2 and parts[1] == '802-11-wireless' and parts[0] not in (NM_CLIENT_CON, NM_AP_CON):
|
||||||
nm('con', 'mod', parts[0], 'connection.autoconnect', 'no')
|
nm('con', 'delete', parts[0])
|
||||||
log.info(f'Autoconnect für Fremdprofil deaktiviert: {parts[0]}')
|
log.info(f'Fremdprofil gelöscht: {parts[0]}')
|
||||||
nm('con', 'mod', NM_CLIENT_CON, 'connection.autoconnect', 'yes')
|
|
||||||
|
|
||||||
|
|
||||||
def connect_client_wifi(ssid, password):
|
def connect_client_wifi(ssid, password):
|
||||||
@@ -109,7 +108,6 @@ def connect_client_wifi(ssid, password):
|
|||||||
ok = r.returncode == 0
|
ok = r.returncode == 0
|
||||||
if ok:
|
if ok:
|
||||||
log.info(f'Verbunden mit {ssid}')
|
log.info(f'Verbunden mit {ssid}')
|
||||||
_takeover_wifi_autoconnect()
|
|
||||||
else:
|
else:
|
||||||
log.error(f'WiFi-Verbindung fehlgeschlagen: {r.stderr.strip()}')
|
log.error(f'WiFi-Verbindung fehlgeschlagen: {r.stderr.strip()}')
|
||||||
return ok
|
return ok
|
||||||
@@ -166,34 +164,18 @@ def _wait_for_nm(max_wait: int = 30) -> None:
|
|||||||
def wifi_monitor():
|
def wifi_monitor():
|
||||||
log.info('WiFi-Monitor: warte auf NetworkManager...')
|
log.info('WiFi-Monitor: warte auf NetworkManager...')
|
||||||
_wait_for_nm()
|
_wait_for_nm()
|
||||||
|
_purge_foreign_wifi_profiles()
|
||||||
first_run = True
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
update_wifi_state()
|
update_wifi_state()
|
||||||
with wifi_lock:
|
with wifi_lock:
|
||||||
mode = wifi_state['mode']
|
mode = wifi_state['mode']
|
||||||
current_conn = wifi_state.get('ssid', '')
|
|
||||||
|
|
||||||
cfg = load_cfg()
|
cfg = load_cfg()
|
||||||
picopy_ssid = cfg.get('wifi_ssid', '')
|
|
||||||
|
|
||||||
# Beim ersten Durchlauf: falls ein Fremdprofil (Imager) verbunden ist
|
|
||||||
# und PiCopy eine eigene SSID kennt → zu PiCopy-WiFi wechseln
|
|
||||||
if first_run and mode == 'client' and current_conn != NM_CLIENT_CON and picopy_ssid:
|
|
||||||
log.info(f'Fremdprofil aktiv ({current_conn}), wechsle zu PiCopy-WiFi ({picopy_ssid})...')
|
|
||||||
connected = connect_client_wifi(picopy_ssid, cfg.get('wifi_password', ''))
|
|
||||||
if connected:
|
|
||||||
time.sleep(5)
|
|
||||||
update_wifi_state()
|
|
||||||
with wifi_lock:
|
|
||||||
mode = wifi_state['mode']
|
|
||||||
|
|
||||||
first_run = False
|
|
||||||
|
|
||||||
if mode == 'disconnected':
|
if mode == 'disconnected':
|
||||||
ssid = picopy_ssid
|
ssid = cfg.get('wifi_ssid', '')
|
||||||
pw = cfg.get('wifi_password', '')
|
pw = cfg.get('wifi_password', '')
|
||||||
|
|
||||||
connected = False
|
connected = False
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
1.0.73
|
1.0.74
|
||||||
Reference in New Issue
Block a user