From a0d45828159c3839a034d473c4de0bc14036100e Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Wed, 18 Mar 2026 09:43:20 +0100 Subject: [PATCH] Simplify Hotspot Settings --- .../assets/hotspot_settings.py | 60 +------------------ .../lib/mpos/net/wifi_service.py | 41 ++++--------- 2 files changed, 12 insertions(+), 89 deletions(-) diff --git a/internal_filesystem/builtin/apps/com.micropythonos.hotspot/assets/hotspot_settings.py b/internal_filesystem/builtin/apps/com.micropythonos.hotspot/assets/hotspot_settings.py index e5ab748e..13d8dae0 100644 --- a/internal_filesystem/builtin/apps/com.micropythonos.hotspot/assets/hotspot_settings.py +++ b/internal_filesystem/builtin/apps/com.micropythonos.hotspot/assets/hotspot_settings.py @@ -14,14 +14,7 @@ class HotspotSettings(Activity): DEFAULTS = { "ssid": "MicroPythonOS", "password": "", - "channel": 1, - "hidden": False, - "max_clients": 4, - "authmode": None, - "ip": "192.168.4.1", - "netmask": "255.255.255.0", - "gateway": "192.168.4.1", - "dns": "8.8.8.8", + "authmode": "wpa2", } status_label = None @@ -117,12 +110,8 @@ class HotspotSettings(Activity): "key": "authmode", "ui": "dropdown", "ui_options": [ - ("Auto", None), ("None", "none"), - #("Open", "open"), - #("WPA", "wpa"), ("WPA2", "wpa2"), - #("WPA/WPA2", "wpa_wpa2"), ], "changed_callback": self.toggle_hotspot, }, @@ -139,53 +128,8 @@ class HotspotSettings(Activity): def _format_security_label(self, authmode): labels = { - None: "Auto", "none": "None", - "open": "Open", - #"wpa": "WPA", "wpa2": "WPA2", - #"wpa_wpa2": "WPA/WPA2", } - return labels.get(authmode, "Auto") + return labels.get(authmode, "WPA2") - -''' -# These settings are too much: -{ - "title": "Channel", - "key": "channel", - "placeholder": "Wi-Fi channel, e.g. 1", -}, -{ - "title": "Hidden Network", - "key": "hidden", - "ui": "radiobuttons", - "ui_options": [("Visible", "False"), ("Hidden", "True")], - "changed_callback": self.toggle_hotspot, -}, -{ - "title": "Max Clients", - "key": "max_clients", - "placeholder": "Max connections, e.g. 4", -}, -{ - "title": "IP Address", - "key": "ip", - "placeholder": "Hotspot IP, e.g. 192.168.4.1", -}, -{ - "title": "Netmask", - "key": "netmask", - "placeholder": "Netmask, e.g. 255.255.255.0", -}, -{ - "title": "Gateway", - "key": "gateway", - "placeholder": "Gateway, e.g. 192.168.4.1", -}, -{ - "title": "DNS", - "key": "dns", - "placeholder": "DNS, e.g. 8.8.8.8", -}, -''' diff --git a/internal_filesystem/lib/mpos/net/wifi_service.py b/internal_filesystem/lib/mpos/net/wifi_service.py index ec932533..6037cb26 100644 --- a/internal_filesystem/lib/mpos/net/wifi_service.py +++ b/internal_filesystem/lib/mpos/net/wifi_service.py @@ -58,34 +58,23 @@ class WifiService: "enabled": prefs.get_bool("enabled", False), "ssid": prefs.get_string("ssid", "MicroPythonOS"), "password": prefs.get_string("password", ""), - "channel": prefs.get_int("channel", 1), - "hidden": prefs.get_bool("hidden", False), - "max_clients": prefs.get_int("max_clients", 4), - "authmode": prefs.get_string("authmode", None), - "ip": prefs.get_string("ip", "192.168.4.1"), - "netmask": prefs.get_string("netmask", "255.255.255.0"), - "gateway": prefs.get_string("gateway", "192.168.4.1"), - "dns": prefs.get_string("dns", "8.8.8.8"), + "authmode": prefs.get_string("authmode", "wpa2"), } @staticmethod def _resolve_hotspot_authmode(net, password, authmode_value): - if authmode_value is None: - if password: - return net.AUTH_WPA_WPA2_PSK - return net.AUTH_OPEN if isinstance(authmode_value, int): return authmode_value if isinstance(authmode_value, str): authmode_key = authmode_value.lower().strip() - mapping = { - "open": net.AUTH_OPEN, - "wpa": net.AUTH_WPA_PSK, - "wpa2": net.AUTH_WPA2_PSK, - "wpa-wpa2": net.AUTH_WPA_WPA2_PSK, - } - return mapping.get(authmode_key, net.AUTH_WPA_WPA2_PSK) - return net.AUTH_WPA_WPA2_PSK + if authmode_key == "none": + return net.AUTH_OPEN + return net.AUTH_WPA2_PSK + if authmode_value is None: + if password: + return net.AUTH_WPA2_PSK + return net.AUTH_OPEN + return net.AUTH_WPA2_PSK @staticmethod def enable_hotspot(network_module=None): @@ -116,23 +105,13 @@ class WifiService: ap_config = { "essid": config.get("ssid"), - "channel": config.get("channel"), - "hidden": config.get("hidden"), - "max_clients": config.get("max_clients"), "authmode": authmode, } if config.get("password"): ap_config["password"] = config.get("password") ap.config(**ap_config) - ap.ifconfig( - ( - config.get("ip"), - config.get("netmask"), - config.get("gateway"), - config.get("dns"), - ) - ) + ap.ifconfig(("192.168.4.1", "255.255.255.0", "192.168.4.1", "8.8.8.8")) WifiService.hotspot_enabled = True print("WifiService: Hotspot enabled")