Skip to content

Commit

Permalink
Improve wifi listing when in Access Point mode
Browse files Browse the repository at this point in the history
Disable Access Point when starting up and it is already activated to be able
to run a success full wifi scan with available networks.

When activating the Access Point do a wifi scan and keep the available networks
in the network status. While Access Point is active only provide the cached
network list to be able to connect to them (no further scanning is possible
in this situation).
  • Loading branch information
ohinckel committed Dec 24, 2022
1 parent 74abd9b commit 86ccbbb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 6 additions & 4 deletions framarama/base/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@ def network_connect(self, name):
self._network['profile'] = name
self._network['networks'] = None

def network_status(self, name):
self._network
def network_status(self):
return self._network

def network_ap_toggle(self):
self.run_capability(FrontendCapability.NET_TOGGLE_AP)
Expand All @@ -281,7 +281,8 @@ def network_verify(self):
self._network['started'] = timezone.now()
logger.info("Checking network connectivity ...")
if _ap_active:
logger.info("Access Point active!")
logger.info("Access Point active - disabling first!")
self.network_ap_toggle()
if _ap_active:
return False
_profile_list = [_name for _name in _profile_list if _profile_list[_name]['active']]
Expand All @@ -290,12 +291,13 @@ def network_verify(self):
_previous = self._network['previous']
if _previous is None:
logger.info("Not connected within 30 seconds and no previous network available - starting access point")
self._network['networks'] = _frontend_device.run_capability(frontend.FrontendCapability.NET_WIFI_LIST)
self._network['networks'] = self.run_capability(FrontendCapability.NET_WIFI_LIST)
self.network_ap_toggle()
self._network['connected'] = timezone.now()
else:
logger.info("Not connected within 30 seconds - try to connect previous network {}".format(_previous))
self._network['profile'] = None
self._network['previous'] = None
self.network_connect(_previous)
else:
logger.info("Not connected!")
Expand Down
5 changes: 4 additions & 1 deletion frontend/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,10 @@ def _get(self, request, *args, **kwargs):
elif _action == 'wifi.list':
_profiles = _frontend_device.run_capability(frontend.FrontendCapability.NET_PROFILE_LIST)
_ap_active = frontend.FrontendCapability.nmcli_ap_active(_profiles)
_networks = _frontend_device.run_capability(frontend.FrontendCapability.NET_WIFI_LIST)
if _ap_active:
_networks = _frontend_device.network_status()['networks']
else:
_networks = _frontend_device.run_capability(frontend.FrontendCapability.NET_WIFI_LIST)
if 'framarama' in _profiles:
del _profiles['framarama']
_networks.update({_name: {'ssid': _name, 'active': False} for _name in _profiles if _name not in _networks})
Expand Down

0 comments on commit 86ccbbb

Please sign in to comment.