Skip to content

Commit 56b9c21

Browse files
committed
nmcli legacy for ubuntu 16.04
1 parent c682199 commit 56b9c21

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

mozloc.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@
1616
from time import sleep
1717

1818
URL='https://location.services.mozilla.com/v1/geolocate?key=test'
19-
NMCMD = ['nmcli','-g','SSID,BSSID,FREQ,SIGNAL','device','wifi']
19+
NMCMD = ['nmcli','-g','SSID,BSSID,FREQ,SIGNAL','device','wifi'] # Debian stretch, Ubuntu 17.10
20+
NMLEG = ['nmcli','-t','-f','SSID,BSSID,FREQ,SIGNAL','device','wifi'] # ubuntu 16.04
2021
NMSCAN = ['nmcli','device','wifi','rescan']
2122

2223

2324
def get_nmcli():
2425

2526

26-
ret = subprocess.check_output(NMCMD)
27+
ret = subprocess.check_output(NMLEG)
2728
sleep(0.5) # nmcli crashed for less than about 0.2 sec.
2829
try:
2930
subprocess.check_call(NMSCAN) # takes several seconds to update, so do it now.
@@ -72,17 +73,19 @@ def get_nmcli():
7273
from argparse import ArgumentParser
7374
p = ArgumentParser()
7475
p.add_argument('logfile',help='logfile to append location to',nargs='?')
76+
p.add_argument('-T','--cadence',help='how often to ping [sec]. Some laptops cannot go faster than 30 sec.',
77+
default=60,type=float)
7578
p = p.parse_args()
7679

77-
T = 25 # nmcli fastest allowed polling cadence: crashes at 20 sec. OK at 25 sec?
80+
T = p.cadence
7881

7982
logfile = p.logfile
8083

8184
print('updating every {} seconds'.format(T))
8285
while True:
8386
loc = get_nmcli()
8487
if loc is None:
85-
sleep(T)
88+
sleep(p.T)
8689
continue
8790

8891
stat = '{} {} {} {} {}'.format(loc['t'].strftime('%xT%X'),

0 commit comments

Comments
 (0)