From 93a7bc17920f70932cd045c44925356dd83f9766 Mon Sep 17 00:00:00 2001 From: Thomas Klaehn Date: Mon, 21 Mar 2016 09:33:52 +0100 Subject: [PATCH] wifi fieldstrength class and test added --- wifi_fieldstrength.py | 20 ++++++++++++++++++++ wifi_fieldstrength_test.py | 10 ++++++++++ 2 files changed, 30 insertions(+) create mode 100644 wifi_fieldstrength.py create mode 100755 wifi_fieldstrength_test.py 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)