wifi fieldstrength class and test added
This commit is contained in:
parent
241281ef99
commit
93a7bc1792
20
wifi_fieldstrength.py
Normal file
20
wifi_fieldstrength.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
from re import match, sub
|
||||||
|
|
||||||
|
class wifi_fieldstrength:
|
||||||
|
def __init__(self, name = "wlan0"):
|
||||||
|
self.name = name
|
||||||
|
self.wf_name = "/proc/net/wireless"
|
||||||
|
|
||||||
|
def read(self):
|
||||||
|
ret = False
|
||||||
|
f = open(self.wf_name, "r")
|
||||||
|
for line in f:
|
||||||
|
line = line.strip()
|
||||||
|
mstr = "^" + self.name
|
||||||
|
if match(mstr, line):
|
||||||
|
line = sub("\s+", " ", line)
|
||||||
|
tmp = line.split(" ")
|
||||||
|
tmp[3] = sub("\.", "", tmp[3])
|
||||||
|
ret = int(tmp[3])
|
||||||
|
return ret
|
10
wifi_fieldstrength_test.py
Executable file
10
wifi_fieldstrength_test.py
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
#!/usr/bin/python2
|
||||||
|
|
||||||
|
from wifi_fieldstrength import wifi_fieldstrength
|
||||||
|
from time import sleep
|
||||||
|
|
||||||
|
wf = wifi_fieldstrength("wlan0")
|
||||||
|
|
||||||
|
while(True):
|
||||||
|
print "Field strength: " + str(wf.read()) + " dBm"
|
||||||
|
sleep(1)
|
Loading…
Reference in New Issue
Block a user