wifi fieldstrength class and test added

This commit is contained in:
Thomas Klaehn 2016-03-21 09:33:52 +01:00 committed by Thomas Klaehn
parent 241281ef99
commit 93a7bc1792
2 changed files with 30 additions and 0 deletions

20
wifi_fieldstrength.py Normal file
View 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
View 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)