Skip to content

Commit c99d356

Browse files
committed
ISO8601-time
1 parent cf115da commit c99d356

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

README.md

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# mozilla-location-python
22
Uses nmcli on Linux in a short, simple Mozilla Location Services with Wifi from Python.
33
Goal was to be as simple as possible.
4-
Works with Python 2.7 and 3.
4+
Works with Python ≥ 3.6.
55

66
## Install
77
```sh
@@ -15,7 +15,7 @@ Linux system with NetworkManager (e.g. Ubuntu, Raspberry Pi, etc.).
1515

1616
## Usage
1717

18-
./mozloc.py
18+
./MozLoc.py
1919

2020
Returns `dict` containing `lat` `lng` `accuracy` `N BSSIDs heard`.
2121
In urban areas, accuracy ~ 5 - 100 meters.
@@ -29,6 +29,11 @@ You can display your logged data in Google Earth or other KML value after conver
2929
with
3030

3131
pip install simplekml
32+
33+
Note that your time MUST be in ISO 8601 format or some KML reading programs such as Google Earth will just show a blank file.
34+
E.g.
35+
36+
2016-07-24T12:34:56
3237

3338

3439
## Contributing

mozloc/__init__.py

+10-12
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
NMSCAN = ['nmcli','device','wifi','rescan']
1414
HEADER='time lat lon accuracy NumBSSIDs'
1515

16-
16+
# %%
1717
def logwifiloc(T:float, logfile:Path):
1818

1919
if logfile:
@@ -30,7 +30,7 @@ def logwifiloc(T:float, logfile:Path):
3030
sleep(T)
3131
continue
3232

33-
stat = f'{loc["t"].strftime("%xT%X")} {loc["lat"]} {loc["lng"]} {loc["accuracy"]:.1f} {loc["N"]:02d}'
33+
stat = f'{loc["t"].isoformat(timespec="seconds")} {loc["lat"]} {loc["lng"]} {loc["accuracy"]:.1f} {loc["N"]:02d}'
3434
print(stat)
3535

3636
if logfile:
@@ -39,14 +39,14 @@ def logwifiloc(T:float, logfile:Path):
3939

4040
sleep(T)
4141

42-
42+
# %%
4343
def get_nmcli():
4444

4545

46-
ret = subprocess.check_output(NMLEG, universal_newlines=True)
46+
ret = subprocess.check_output(NMLEG, universal_newlines=True, timeout=1.)
4747
sleep(0.5) # nmcli crashed for less than about 0.2 sec.
4848
try:
49-
subprocess.check_call(NMSCAN) # takes several seconds to update, so do it now.
49+
subprocess.check_call(NMSCAN, timeout=1.) # takes several seconds to update, so do it now.
5050
except subprocess.CalledProcessError as e:
5151
logging.error(f'consider slowing scan cadence. {e}')
5252

@@ -101,14 +101,12 @@ def csv2kml(csvfn:Path, kmlfn:Path):
101101
# %% write KML
102102
"""
103103
http://simplekml.readthedocs.io/en/latest/geometries.html#gxtrack
104+
https://simplekml.readthedocs.io/en/latest/kml.html#id1
105+
https://simplekml.readthedocs.io/en/latest/geometries.html#simplekml.GxTrack
104106
"""
105-
kml = Kml(name='My Kml',open=1)
106-
107-
108-
doc = kml.newdocument(name='Mozilla Location Services')
109-
fol = doc.newfolder(name='Tracks')
110-
trk = fol.newgxtrack(name='My Track')
111-
trk.newwhen(t) # list of times
107+
kml = Kml(name='My Kml')
108+
trk = kml.newgxtrack(name='My Track')
109+
trk.newwhen(t) # list of times. MUST be format 2010-05-28T02:02:09Z
112110
trk.newgxcoord(lla.tolist()) #list of lon,lat,alt, NOT ndarray!
113111

114112
# just a bunch of points

0 commit comments

Comments
 (0)