mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 06:56:18 -05:00
Limiting attempts to start the hotspot.
This commit is contained in:
parent
9d21282eab
commit
eaf4553299
1 changed files with 6 additions and 3 deletions
|
|
@ -45,18 +45,21 @@ def hotspot_status() -> HotspotStatus:
|
|||
return HotspotStatus.unknown
|
||||
|
||||
|
||||
def enable_hotspot():
|
||||
def enable_hotspot(depth: int = 10):
|
||||
"""Turn the Wi-Fi interface into a hotspot.
|
||||
|
||||
If Wi-Fi is already running, replace that with a hotspot.
|
||||
"""
|
||||
if depth < 0:
|
||||
raise RuntimeError(f'Failed to start hotspot!')
|
||||
|
||||
status = hotspot_status()
|
||||
logger.info(f'Hotspot status: {status}')
|
||||
|
||||
if status == HotspotStatus.connected:
|
||||
logger.info('Hotspot already connected. Rebooting hotspot.')
|
||||
disable_hotspot()
|
||||
return enable_hotspot()
|
||||
return enable_hotspot(depth=depth - 1)
|
||||
elif status == HotspotStatus.disconnected:
|
||||
# Radio is on, but not connected. Good, turn it into a hotspot.
|
||||
cmd = (SUDO_BIN, NMCLI_BIN, 'device', 'wifi', 'hotspot', 'ifname', WROLPI_CONFIG.hotspot_device,
|
||||
|
|
@ -69,7 +72,7 @@ def enable_hotspot():
|
|||
cmd = (SUDO_BIN, NMCLI_BIN, 'radio', 'wifi', 'on')
|
||||
subprocess.check_call(cmd)
|
||||
logger.info('Turned on hotspot radio.')
|
||||
return enable_hotspot()
|
||||
return enable_hotspot(depth=depth - 1)
|
||||
elif status == HotspotStatus.unknown:
|
||||
logger.error('Cannot enable hotspot with unknown status!')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue