Skip to content

Commit b36ff9d

Browse files
WifiService: disable hotspot when connecting to access point
1 parent e65c48c commit b36ff9d

3 files changed

Lines changed: 86 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Frameworks:
2222
- Websocket library: renamed to uaiowebsocket to avoid conflicts
2323

2424
OS:
25-
- ESP32 boards: bundle WebREPL (disabled by default, password protected, can be enabled in Settings)
25+
- ESP32 boards: bundle WebREPL (not started by default) to offer remote MicroPython shell over the network, accessible through webbrowser
2626
- New board support: LilyGo T-Display-S3 (physical and emulated by QEMU)
2727
- New board support: LilyGo T-Watch S3 Plus
2828
- New board support: M5Stack Fire

internal_filesystem/lib/mpos/net/wifi_service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@ def attempt_connecting(ssid, password, network_module=None, time_module=None):
257257

258258
time_mod = time_module if time_module else time
259259

260+
if WifiService.is_hotspot_enabled(network_module=network_module):
261+
WifiService._needs_hotspot_restore = False
262+
WifiService.disable_hotspot(network_module=network_module)
263+
260264
# Desktop mode - simulate successful connection
261265
if WifiService._is_desktop_mode(network_module):
262266
print("WifiService: Desktop mode, simulating connection...")
@@ -268,10 +272,6 @@ def attempt_connecting(ssid, password, network_module=None, time_module=None):
268272
net = WifiService._get_network_module(network_module)
269273

270274
try:
271-
if WifiService.is_hotspot_enabled(network_module=network_module):
272-
WifiService._needs_hotspot_restore = True
273-
WifiService.disable_hotspot(network_module=network_module)
274-
275275
wlan = WifiService._get_sta_wlan(net)
276276
wlan.connect(ssid, password)
277277

tests/test_graphical_hotspot_then_station.py

Lines changed: 81 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,56 @@
1010
"""
1111

1212
import unittest
13+
import time
1314
import lvgl as lv
1415
import mpos.ui
15-
from mpos import AppManager, WifiService, wait_for_render, click_button, print_screen_labels
16+
from mpos import (
17+
AppManager,
18+
WifiService,
19+
wait_for_render,
20+
click_button,
21+
print_screen_labels,
22+
get_widget_coords,
23+
simulate_click,
24+
)
1625

1726

1827
class TestGraphicalHotspotThenStation(unittest.TestCase):
1928
"""Test hotspot start flow via the hotspot settings app."""
2029

30+
def _find_first_list_item(self, screen):
31+
def find_list(node):
32+
try:
33+
if node.__class__.__name__ == "list":
34+
return node
35+
except Exception:
36+
pass
37+
try:
38+
if hasattr(node, "add_button") and hasattr(node, "get_child_count"):
39+
return node
40+
except Exception:
41+
pass
42+
try:
43+
child_count = node.get_child_count()
44+
except Exception:
45+
child_count = 0
46+
for i in range(child_count):
47+
child = node.get_child(i)
48+
found = find_list(child)
49+
if found:
50+
return found
51+
return None
52+
53+
wifi_list = find_list(screen)
54+
if wifi_list is None:
55+
return None
56+
try:
57+
if wifi_list.get_child_count() < 1:
58+
return None
59+
return wifi_list.get_child(0)
60+
except Exception:
61+
return None
62+
2163
def tearDown(self):
2264
"""Clean up after each test method."""
2365
try:
@@ -64,6 +106,44 @@ def test_hotspot_start_button_enables_hotspot(self):
64106
"Hotspot should be enabled after pressing Start",
65107
)
66108

109+
result = AppManager.start_app("com.micropythonos.settings.wifi")
110+
self.assertTrue(result, "Failed to start WiFi settings app")
111+
wait_for_render(iterations=20)
112+
113+
screen = lv.screen_active()
114+
print("\nWiFi screen labels (before scan wait):")
115+
print_screen_labels(screen)
116+
117+
print("\nWaiting 10 seconds for WiFi scan to finish...")
118+
time.sleep(10)
119+
wait_for_render(iterations=20)
120+
121+
screen = lv.screen_active()
122+
print("\nWiFi screen labels (after scan wait):")
123+
print_screen_labels(screen)
124+
125+
first_item = self._find_first_list_item(screen)
126+
self.assertIsNotNone(first_item, "Could not find first WiFi access point")
127+
128+
coords = get_widget_coords(first_item)
129+
if coords:
130+
print(f"Clicking first WiFi access point at ({coords['center_x']}, {coords['center_y']})")
131+
first_item.send_event(lv.EVENT.CLICKED, None)
132+
else:
133+
first_item.send_event(lv.EVENT.CLICKED, None)
134+
wait_for_render(iterations=40)
135+
136+
self.assertTrue(
137+
click_button("Connect"),
138+
"Could not find Connect button in WiFi edit screen",
139+
)
140+
wait_for_render(iterations=40)
141+
142+
self.assertFalse(
143+
WifiService.is_hotspot_enabled(),
144+
"Hotspot should be disabled after connecting to a WiFi access point",
145+
)
146+
67147
print("\n=== Hotspot start-flow test completed ===")
68148

69149

0 commit comments

Comments
 (0)