-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
macOS: work with macOS >= 14.4 again.
rename get_signal() => scan_signal() rename parse_signal() => get_signal()
- Loading branch information
Showing
11 changed files
with
139 additions
and
110 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
from .base import log_wifi_loc | ||
from .modules import get_signal, parse_signal, cli_config_check | ||
from .modules import get_signal, scan_signal, config_check | ||
|
||
__version__ = "1.7.0" | ||
__version__ = "1.8.0" | ||
|
||
__all__ = ["log_wifi_loc", "get_signal", "parse_signal", "cli_config_check"] | ||
__all__ = ["log_wifi_loc", "get_signal", "scan_signal", "config_check"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# /usr/bin/env python3 | ||
""" | ||
MUST USE SYSTEM PYTHON /usr/bin/python3 | ||
DON'T USE sudo as LocationServices Python won't pop up. | ||
TODO: even with all this, BSSID is still (null) / None | ||
LocationServices Python app becomes available to enable in | ||
Settings > Privacy > Location Services | ||
pip install pyobjc | ||
from https://forums.developer.apple.com/forums/thread/748161?answerId=782574022#782574022 | ||
Ref: https://docs.python.org/3/using/mac.html#gui-programming | ||
""" | ||
|
||
import CoreLocation | ||
import time | ||
import logging | ||
import pandas | ||
|
||
import objc | ||
|
||
|
||
def config_check() -> bool: | ||
""" | ||
Need authorization to get BSSID | ||
""" | ||
|
||
mgr = CoreLocation.CLLocationManager.alloc().init() | ||
# mgr = CoreLocation.CLLocationManager.new() | ||
# mgr.requestAlwaysAuthorization() | ||
mgr.startUpdatingLocation() | ||
|
||
max_wait = 10 | ||
# Get the current authorization status for Python | ||
# https://stackoverflow.com/a/75843844 | ||
for i in range(1, max_wait): | ||
s = mgr.authorizationStatus() | ||
if s in {3, 4}: | ||
print("Python has been authorized for location services") | ||
return True | ||
if i == max_wait - 1: | ||
logging.error("Unable to obtain authorization") | ||
return False | ||
print(f"Waiting for authorization... do you see the Location Services popup window? {s}") | ||
time.sleep(0.5) | ||
|
||
return False | ||
|
||
|
||
def get_signal(networks): | ||
# Get the current location | ||
|
||
dat: list[dict[str, str]] = [] | ||
|
||
for network in networks: | ||
# print(f"{network.ssid()} {network.bssid()} {network.rssi()} channel {network.channel()}") | ||
d = {"ssid": network.ssid(), "signalStrength": network.rssi()} | ||
if network.bssid() is not None: | ||
d["macAddress"] = network.bssid() | ||
dat.append(d) | ||
|
||
return pandas.DataFrame(dat) | ||
|
||
|
||
def scan_signal(): | ||
|
||
bundle_path = "/System/Library/Frameworks/CoreWLAN.framework" | ||
|
||
objc.loadBundle("CoreWLAN", bundle_path=bundle_path, module_globals=globals()) | ||
|
||
# https://developer.apple.com/documentation/corewlan/cwinterface | ||
# iface = CWInterface.interface() # not recommended, low-level | ||
# https://developer.apple.com/documentation/corewlan/cwwificlient | ||
iface = CoreLocation.CWWiFiClient.sharedWiFiClient().interface() | ||
|
||
logging.info(f"WiFi interface {iface.interfaceName()}") | ||
|
||
# need to run once to warmup -- otherwise all SSID are "(null)" | ||
iface.scanForNetworksWithName_includeHidden_error_(None, True, None) | ||
|
||
networks, error = iface.scanForNetworksWithName_includeHidden_error_(None, True, None) | ||
|
||
return networks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
import sys | ||
import platform | ||
|
||
|
||
match sys.platform: | ||
case "win32": | ||
from .netsh import cli_config_check, get_signal, parse_signal | ||
case "linux": | ||
from .netman import cli_config_check, get_signal, parse_signal | ||
case "darwin": | ||
from .airport import cli_config_check, get_signal, parse_signal | ||
case _: | ||
raise ImportError(f"MozLoc doesn't work with platform {sys.platform}") | ||
if sys.platform == "win32": | ||
from .netsh import config_check, get_signal, scan_signal | ||
elif sys.platform == "linux": | ||
from .netman import config_check, get_signal, scan_signal | ||
elif sys.platform == "darwin": | ||
if tuple(map(int, platform.mac_ver()[0].split("."))) < (14, 4): | ||
from .airport import config_check, get_signal, scan_signal | ||
else: | ||
from .macos_corelocation import config_check, get_signal, scan_signal | ||
else: | ||
raise ImportError(f"MozLoc doesn't work with platform {sys.platform}") | ||
|
||
|
||
__all__ = ["cli_config_check", "get_signal", "parse_signal"] | ||
__all__ = ["config_check", "get_signal", "scan_signal"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
import os | ||
import pandas | ||
import mozloc | ||
|
||
is_ci = os.environ.get("CI", "").lower() == "true" | ||
|
||
|
||
@pytest.mark.skipif(is_ci, reason="CI doesn't usually have WiFi") | ||
def test_signal(): | ||
if not mozloc.config_check(): | ||
pytest.skip("WiFi not available") | ||
|
||
loc = mozloc.get_signal(mozloc.scan_signal()) | ||
|
||
assert isinstance(loc, pandas.DataFrame) | ||
assert -130 < int(loc["signalStrength"][0]) < 0, "impossible RSSI" |
This file was deleted.
Oops, something went wrong.