Skip to content

Commit 9cbfedb

Browse files
committed
Re-read WiFi conf at first request
At the time of container start, it is assumed that the WiFi conf available might not be the “correct” one: it can be changed once the containers have started, when `ap` step is ran. This thus re-reads the conf upon first /wifi/ request so it's using the correct one. Given requests only come via WiFi, it's not possible that this would happen before the WiFi conf is applied. Fixes #1
1 parent 050e4c8 commit 9cbfedb

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- WiFi profile not representative on Pi3B (#1)
13+
1014
### Changed
1115

1216
- Defaulting to INFO log leve unless `DEBUG` ENV is present

src/adminui/context.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Context:
2727
wifi_ssid: str = "Kiwix Hotspot"
2828
wifi_passphrase: str | None = None
2929
wifi_profile: str = "perf"
30+
wifi_conf_read: bool = False
3031

3132
sshd_enabled: bool = False
3233
kiosk_enabled: bool = False

src/adminui/setup.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,27 @@ def complete_wifi_conf_from_hostapd(conf: WifiConf) -> WifiConf:
149149
return conf
150150

151151

152+
def get_wifi_conf() -> WifiConf:
153+
# read wifi conf from offspot.yaml if present
154+
wifi_conf = get_wifi_conf_from_offspot_yaml()
155+
if not wifi_conf.is_complete:
156+
# otherwise read from hostapd.conf
157+
wifi_conf = complete_wifi_conf_from_hostapd(wifi_conf)
158+
return wifi_conf
159+
160+
152161
def prepare_context():
153162
# read tld, domain, prefixes from compose
154163
compose_data = get_from_compose()
155164

156165
# read capabilities
157166
capabilities = get_capabilities_from_config()
158167

159-
# read wifi conf from offspot.yaml if present
160-
wifi_conf = get_wifi_conf_from_offspot_yaml()
161-
if not wifi_conf.is_complete:
162-
# otherwise read from hostapd.conf
163-
wifi_conf = complete_wifi_conf_from_hostapd(wifi_conf)
168+
# read wifi conf
169+
# /!\ at this stage, hostapd.conf might not exists
170+
# and thus conf might be composed of ap: in offspot.yamll or defaults
171+
# /!\ it's possible ap: references perf profile but ap.py will switch to coverage
172+
wifi_conf = get_wifi_conf()
164173

165174
# request sshd service status from bridge
166175
try:

src/adminui/wifi.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from adminui.auth.views import login_required
1414
from adminui.constants import TEMPLATES_DIR, logger
1515
from adminui.context import Context
16+
from adminui.setup import get_wifi_conf
1617
from adminui.utils import (
1718
ValidateResult,
1819
read_latest_conf,
@@ -69,8 +70,23 @@ def update_wifi_config(data: WifiFormData):
6970
save_offspot_conf(config)
7071

7172

73+
def ensure_wifi_conf_read():
74+
if context.wifi_conf_read:
75+
return
76+
wifi_conf = get_wifi_conf()
77+
if not wifi_conf.is_complete:
78+
logger.error(f"Incomplete WiFiConf at runtime: {wifi_conf!s}")
79+
context.wifi_profile = str(wifi_conf.profile)
80+
context.wifi_ssid = str(wifi_conf.ssid)
81+
context.wifi_passphrase = (
82+
str(wifi_conf.passphrase) if wifi_conf.passphrase else None
83+
)
84+
context.wifi_conf_read = True
85+
86+
7287
@router.get("/", name="wifi_config")
7388
def config(request: Request, session: Session = Depends(login_required)) -> Response:
89+
ensure_wifi_conf_read()
7490
return templates.TemplateResponse(
7591
request=request,
7692
name="wifi/config.html",
@@ -84,6 +100,7 @@ def config_update(
84100
data: Annotated[WifiFormData, Form()],
85101
session: Session = Depends(login_required),
86102
) -> Response:
103+
ensure_wifi_conf_read()
87104
is_valid, errors = data.validate()
88105
if is_valid:
89106
try:

0 commit comments

Comments
 (0)