diff --git a/wifi_fieldstrength.py b/wifi_fieldstrength.py new file mode 100644 index 0000000..2a49715 --- /dev/null +++ b/wifi_fieldstrength.py @@ -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 diff --git a/wifi_fieldstrength_test.py b/wifi_fieldstrength_test.py new file mode 100755 index 0000000..becb967 --- /dev/null +++ b/wifi_fieldstrength_test.py @@ -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)