Skip to content

Commit 5b50ce8

Browse files
Add Hotspot configuration
1 parent ff21743 commit 5b50ce8

10 files changed

Lines changed: 717 additions & 307 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "Hotspot",
3+
"publisher": "MicroPythonOS",
4+
"short_description": "Configure Wi-Fi hotspot settings.",
5+
"long_description": "Configure and toggle the device Wi-Fi hotspot, including SSID, security, and network options.",
6+
"icon_url": "https://apps.micropythonos.com/apps/com.micropythonos.hotspot/icons/com.micropythonos.hotspot_0.1.0_64x64.png",
7+
"download_url": "https://apps.micropythonos.com/apps/com.micropythonos.hotspot/mpks/com.micropythonos.hotspot_0.1.0.mpk",
8+
"fullname": "com.micropythonos.hotspot",
9+
"version": "0.1.0",
10+
"category": "networking",
11+
"activities": [
12+
{
13+
"entrypoint": "assets/hotspot.py",
14+
"classname": "Hotspot",
15+
"intent_filters": [
16+
{
17+
"action": "main",
18+
"category": "launcher"
19+
}
20+
]
21+
}
22+
]
23+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
import lvgl as lv
2+
3+
from mpos import Activity, Intent, SettingsActivity, SharedPreferences, WifiService
4+
5+
6+
class Hotspot(SettingsActivity):
7+
"""
8+
Hotspot configuration app.
9+
10+
Uses SettingsActivity to render and edit hotspot preferences stored under
11+
com.micropythonos.system.hotspot.
12+
"""
13+
14+
DEFAULTS = {
15+
"enabled": False,
16+
"ssid": "MicroPythonOS",
17+
"password": "",
18+
"channel": 1,
19+
"hidden": False,
20+
"max_clients": 4,
21+
"authmode": None,
22+
"ip": "192.168.4.1",
23+
"netmask": "255.255.255.0",
24+
"gateway": "192.168.4.1",
25+
"dns": "8.8.8.8",
26+
}
27+
28+
def getIntent(self):
29+
prefs = SharedPreferences("com.micropythonos.system.hotspot", defaults=self.DEFAULTS)
30+
intent = Intent()
31+
intent.putExtra("prefs", prefs)
32+
intent.putExtra(
33+
"settings",
34+
[
35+
{
36+
"title": "Hotspot Enabled",
37+
"key": "enabled",
38+
"ui": "radiobuttons",
39+
"ui_options": [("On", "True"), ("Off", "False")],
40+
"changed_callback": self.toggle_hotspot,
41+
},
42+
{
43+
"title": "Network Name (SSID)",
44+
"key": "ssid",
45+
"placeholder": "Hotspot SSID",
46+
},
47+
{
48+
"title": "Password",
49+
"key": "password",
50+
"placeholder": "Leave empty for open network",
51+
},
52+
{
53+
"title": "Channel",
54+
"key": "channel",
55+
"placeholder": "Wi-Fi channel, e.g. 1",
56+
},
57+
{
58+
"title": "Hidden Network",
59+
"key": "hidden",
60+
"ui": "radiobuttons",
61+
"ui_options": [("Visible", "False"), ("Hidden", "True")],
62+
"changed_callback": self.toggle_hotspot,
63+
},
64+
{
65+
"title": "Max Clients",
66+
"key": "max_clients",
67+
"placeholder": "Max connections, e.g. 4",
68+
},
69+
{
70+
"title": "Auth Mode",
71+
"key": "authmode",
72+
"ui": "dropdown",
73+
"ui_options": [
74+
("Auto", None),
75+
("Open", "open"),
76+
("WPA", "wpa"),
77+
("WPA2", "wpa2"),
78+
("WPA/WPA2", "wpa_wpa2"),
79+
],
80+
"changed_callback": self.toggle_hotspot,
81+
},
82+
{
83+
"title": "IP Address",
84+
"key": "ip",
85+
"placeholder": "Hotspot IP, e.g. 192.168.4.1",
86+
},
87+
{
88+
"title": "Netmask",
89+
"key": "netmask",
90+
"placeholder": "Netmask, e.g. 255.255.255.0",
91+
},
92+
{
93+
"title": "Gateway",
94+
"key": "gateway",
95+
"placeholder": "Gateway, e.g. 192.168.4.1",
96+
},
97+
{
98+
"title": "DNS",
99+
"key": "dns",
100+
"placeholder": "DNS, e.g. 8.8.8.8",
101+
},
102+
],
103+
)
104+
return intent
105+
106+
def toggle_hotspot(self, new_value):
107+
enabled_value = self.prefs.get_string("enabled", "False")
108+
should_enable = str(enabled_value).lower() in ("true", "1", "yes", "on")
109+
if should_enable:
110+
WifiService.enable_hotspot()
111+
else:
112+
WifiService.disable_hotspot()
6.09 KB
Loading

internal_filesystem/builtin/apps/com.micropythonos.settings/assets/settings.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ def onCreate(self):
1212
AppManager.start_app("com.micropythonos.wifi")
1313

1414

15+
class LaunchHotspot(Activity):
16+
17+
def onCreate(self):
18+
AppManager.start_app("com.micropythonos.hotspot")
19+
20+
1521
class Settings(SettingsActivity):
1622

1723
"""Override getIntent to provide prefs and settings via Intent extras"""
@@ -46,6 +52,7 @@ def getIntent(self):
4652
intent.putExtra("prefs", SharedPreferences("com.micropythonos.settings"))
4753
intent.putExtra("settings", [
4854
{"title": "Wi-Fi", "key": "wifi_settings", "ui": "activity", "activity_class": LaunchWiFi},
55+
{"title": "Hotspot", "key": "hotspot_settings", "ui": "activity", "activity_class": LaunchHotspot},
4956
# Basic settings, alphabetically:
5057
{"title": "Light/Dark Theme", "key": "theme_light_dark", "ui": "radiobuttons", "ui_options": [("Light", "light"), ("Dark", "dark")], "changed_callback": self.theme_changed},
5158
{"title": "Theme Color", "key": "theme_primary_color", "placeholder": "HTML hex color, like: EC048C", "ui": "dropdown", "ui_options": theme_colors, "changed_callback": self.theme_changed, "default_value": AppearanceManager.DEFAULT_PRIMARY_COLOR},

0 commit comments

Comments
 (0)