Skip to content

Commit a0d4582

Browse files
Simplify Hotspot Settings
1 parent e19a286 commit a0d4582

2 files changed

Lines changed: 13 additions & 90 deletions

File tree

internal_filesystem/builtin/apps/com.micropythonos.hotspot/assets/hotspot_settings.py

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,7 @@ class HotspotSettings(Activity):
1414
DEFAULTS = {
1515
"ssid": "MicroPythonOS",
1616
"password": "",
17-
"channel": 1,
18-
"hidden": False,
19-
"max_clients": 4,
20-
"authmode": None,
21-
"ip": "192.168.4.1",
22-
"netmask": "255.255.255.0",
23-
"gateway": "192.168.4.1",
24-
"dns": "8.8.8.8",
17+
"authmode": "wpa2",
2518
}
2619

2720
status_label = None
@@ -117,12 +110,8 @@ def _settings_entries(self):
117110
"key": "authmode",
118111
"ui": "dropdown",
119112
"ui_options": [
120-
("Auto", None),
121113
("None", "none"),
122-
#("Open", "open"),
123-
#("WPA", "wpa"),
124114
("WPA2", "wpa2"),
125-
#("WPA/WPA2", "wpa_wpa2"),
126115
],
127116
"changed_callback": self.toggle_hotspot,
128117
},
@@ -139,53 +128,8 @@ def should_show_password(self, setting):
139128

140129
def _format_security_label(self, authmode):
141130
labels = {
142-
None: "Auto",
143131
"none": "None",
144-
"open": "Open",
145-
#"wpa": "WPA",
146132
"wpa2": "WPA2",
147-
#"wpa_wpa2": "WPA/WPA2",
148133
}
149-
return labels.get(authmode, "Auto")
150-
151-
152-
'''
153-
# These settings are too much:
154-
{
155-
"title": "Channel",
156-
"key": "channel",
157-
"placeholder": "Wi-Fi channel, e.g. 1",
158-
},
159-
{
160-
"title": "Hidden Network",
161-
"key": "hidden",
162-
"ui": "radiobuttons",
163-
"ui_options": [("Visible", "False"), ("Hidden", "True")],
164-
"changed_callback": self.toggle_hotspot,
165-
},
166-
{
167-
"title": "Max Clients",
168-
"key": "max_clients",
169-
"placeholder": "Max connections, e.g. 4",
170-
},
171-
{
172-
"title": "IP Address",
173-
"key": "ip",
174-
"placeholder": "Hotspot IP, e.g. 192.168.4.1",
175-
},
176-
{
177-
"title": "Netmask",
178-
"key": "netmask",
179-
"placeholder": "Netmask, e.g. 255.255.255.0",
180-
},
181-
{
182-
"title": "Gateway",
183-
"key": "gateway",
184-
"placeholder": "Gateway, e.g. 192.168.4.1",
185-
},
186-
{
187-
"title": "DNS",
188-
"key": "dns",
189-
"placeholder": "DNS, e.g. 8.8.8.8",
190-
},
191-
'''
134+
return labels.get(authmode, "WPA2")
135+

internal_filesystem/lib/mpos/net/wifi_service.py

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,23 @@ def _get_hotspot_config():
5858
"enabled": prefs.get_bool("enabled", False),
5959
"ssid": prefs.get_string("ssid", "MicroPythonOS"),
6060
"password": prefs.get_string("password", ""),
61-
"channel": prefs.get_int("channel", 1),
62-
"hidden": prefs.get_bool("hidden", False),
63-
"max_clients": prefs.get_int("max_clients", 4),
64-
"authmode": prefs.get_string("authmode", None),
65-
"ip": prefs.get_string("ip", "192.168.4.1"),
66-
"netmask": prefs.get_string("netmask", "255.255.255.0"),
67-
"gateway": prefs.get_string("gateway", "192.168.4.1"),
68-
"dns": prefs.get_string("dns", "8.8.8.8"),
61+
"authmode": prefs.get_string("authmode", "wpa2"),
6962
}
7063

7164
@staticmethod
7265
def _resolve_hotspot_authmode(net, password, authmode_value):
73-
if authmode_value is None:
74-
if password:
75-
return net.AUTH_WPA_WPA2_PSK
76-
return net.AUTH_OPEN
7766
if isinstance(authmode_value, int):
7867
return authmode_value
7968
if isinstance(authmode_value, str):
8069
authmode_key = authmode_value.lower().strip()
81-
mapping = {
82-
"open": net.AUTH_OPEN,
83-
"wpa": net.AUTH_WPA_PSK,
84-
"wpa2": net.AUTH_WPA2_PSK,
85-
"wpa-wpa2": net.AUTH_WPA_WPA2_PSK,
86-
}
87-
return mapping.get(authmode_key, net.AUTH_WPA_WPA2_PSK)
88-
return net.AUTH_WPA_WPA2_PSK
70+
if authmode_key == "none":
71+
return net.AUTH_OPEN
72+
return net.AUTH_WPA2_PSK
73+
if authmode_value is None:
74+
if password:
75+
return net.AUTH_WPA2_PSK
76+
return net.AUTH_OPEN
77+
return net.AUTH_WPA2_PSK
8978

9079
@staticmethod
9180
def enable_hotspot(network_module=None):
@@ -116,23 +105,13 @@ def enable_hotspot(network_module=None):
116105

117106
ap_config = {
118107
"essid": config.get("ssid"),
119-
"channel": config.get("channel"),
120-
"hidden": config.get("hidden"),
121-
"max_clients": config.get("max_clients"),
122108
"authmode": authmode,
123109
}
124110
if config.get("password"):
125111
ap_config["password"] = config.get("password")
126112

127113
ap.config(**ap_config)
128-
ap.ifconfig(
129-
(
130-
config.get("ip"),
131-
config.get("netmask"),
132-
config.get("gateway"),
133-
config.get("dns"),
134-
)
135-
)
114+
ap.ifconfig(("192.168.4.1", "255.255.255.0", "192.168.4.1", "8.8.8.8"))
136115

137116
WifiService.hotspot_enabled = True
138117
print("WifiService: Hotspot enabled")

0 commit comments

Comments
 (0)