Skip to content

Commit 1d2c299

Browse files
committed
add mozloc_signal to dump all current BSSID to CLI
1 parent be89925 commit 1d2c299

File tree

9 files changed

+35
-16
lines changed

9 files changed

+35
-16
lines changed

README.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,17 @@ python -m pip install -e .
2323
## Usage
2424

2525
```sh
26-
python MozLoc.py
26+
MozLoc
2727
```
2828

29-
Returns `dict()` containing `lat` `lng` `accuracy` `N BSSIDs heard`.
30-
In urban areas, accuracy ~ 5 - 100 meters.
29+
Shows `time` `lat` `lng` `accuracy` `N BSSIDs heard`.
30+
In urban areas, accuracy of less than 100 meters is possible.
31+
32+
### dump raw signals
33+
34+
```sh
35+
mozloc_signal
36+
```
3137

3238
### Windows
3339

setup.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,5 @@ io =
4949
[options.entry_points]
5050
console_scripts =
5151
MozLoc = mozloc.__main__:mozilla_location
52+
mozloc_signal = mozloc.__main__:wifi_signal
5253
mozloc_csv2kml = mozloc.__main__:csv2kml

src/mozloc/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
from .base import log_wifi_loc
2-
from .modules import get_cli, cli_config_check
2+
from .modules import get_signal, cli_config_check

src/mozloc/__main__.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,30 @@
77
88
Don't abuse the API or you'll get banned (excessive polling rate)
99
"""
10+
1011
from .base import log_wifi_loc
12+
from .modules import get_signal
13+
14+
import pandas
1115
from argparse import ArgumentParser
1216

1317

18+
def wifi_signal():
19+
20+
wifi = get_signal()
21+
if isinstance(wifi, pandas.DataFrame):
22+
print(wifi)
23+
else:
24+
# list of dict
25+
for s in wifi:
26+
print(s)
27+
28+
1429
def mozilla_location():
15-
"""
16-
output: lat lon [deg] accuracy [m]
17-
"""
1830
p = ArgumentParser()
1931
p.add_argument("logfile", help="logfile to append location to", nargs="?")
2032
p.add_argument(
21-
"-T", "--cadence", help="how often to ping [sec]. Some laptops cannot go faster than 30 sec.", default=60, type=float
33+
"-T", "--cadence", help="how often to update [sec]. Some laptops cannot go faster than 30 sec.", default=60, type=float
2234
)
2335
p.add_argument(
2436
"-url",

src/mozloc/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33
import logging
44

5-
from .modules import get_cli, cli_config_check
5+
from .modules import get_signal, cli_config_check
66
from .web import get_loc_mozilla
77

88
HEADER = "time lat lon accuracy NumBSSIDs"
@@ -23,7 +23,7 @@ def log_wifi_loc(cadence_sec: float, mozilla_url: str, logfile: Path = None):
2323
# nmcli errored for less than about 0.2 sec.
2424
sleep(0.5)
2525
while True:
26-
dat = get_cli()
26+
dat = get_signal()
2727
if len(dat) < 2:
2828
logging.warning(f"cannot locate since at least 2 BSSIDs required\n{dat}")
2929
sleep(cadence_sec)

src/mozloc/modules.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import sys
22

33
if sys.platform == "win32":
4-
from .netsh import cli_config_check, get_cli
4+
from .netsh import cli_config_check, get_signal
55
elif sys.platform == "linux":
6-
from .netman import cli_config_check, get_cli
6+
from .netman import cli_config_check, get_signal
77
else:
8-
raise ImportError(f"MozLoc doesn't yet know how to work with platform {sys.platform}")
8+
raise ImportError(f"MozLoc doesn't work with platform {sys.platform}")

src/mozloc/netman.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def cli_config_check() -> bool:
3838
return False
3939

4040

41-
def get_cli() -> T.List[T.Dict[str, T.Any]]:
41+
def get_signal() -> T.List[T.Dict[str, T.Any]]:
4242

4343
ret = subprocess.run(NMCMD, timeout=1.0)
4444
if ret.returncode != 0:

src/mozloc/netsh.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def cli_config_check() -> bool:
2727
return False
2828

2929

30-
def get_cli() -> T.List[T.Dict[str, T.Any]]:
30+
def get_signal() -> T.List[T.Dict[str, T.Any]]:
3131
""" get signal strength using CLI """
3232
ret = subprocess.run(CMD, timeout=1.0, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
3333
if ret.returncode != 0:

src/mozloc/tests/test_netman.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
def test_nm_loc():
99

1010
mozloc = pytest.importorskip('mozloc')
11-
loc = mozloc.get_cli()
11+
loc = mozloc.get_signal()
1212

1313
assert isinstance(loc, list)
1414
assert isinstance(loc[0], dict)

0 commit comments

Comments
 (0)