Compare commits

...

3 Commits

Author SHA1 Message Date
tkl
2791190503 wifi level via mqtt 2016-08-14 09:27:33 +00:00
tkl
8f80e3f1a8 wireless level udp transmission 2016-08-14 09:21:43 +00:00
tkl
d105436a13 interface to grab wifi informations 2016-08-14 06:11:30 +00:00
4 changed files with 74 additions and 1 deletions

23
mqtt.py Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/python2
import paho.mqtt.client as mqtt
import socket
import time
import wireless
def on_connect(client, data, flags, result):
print "Connected with " + str(result)
topic = "outdoor"
domain = "mower"
host = socket.gethostname()
preamble = topic + "/" + domain + "/" + host
cl = mqtt.Client()
cl.on_connect = on_connect
cl.connect("192.168.178.21", 1883, 60)
cl.loop_start()
w = wireless.wireless("wlan0")
while True:
cl.publish(preamble + "/net/level", str(int(time.time())) + ":" + w.level())
time.sleep(1)

12
test_wireless.py Executable file
View File

@ -0,0 +1,12 @@
#!/usr/bin/python2
import wireless
import time
wf = wireless.wireless("wlan0")
while(True):
print "level: " + wf.level() + " dBm"
print "link: " + wf.link() + " dBm"
print "noise: " + wf.noise() + " dBm"
time.sleep(1)

View File

@ -2,12 +2,15 @@
import socket
import time
import wireless
target = "192.168.178.21"
port = 5005
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
w = wireless.wireless("wlan0")
while 1:
s.sendto("test", (target, port))
msg = "#WIFI:LEVEL:" + w.level()
s.sendto(msg, (target, port))
time.sleep(1)

35
wireless.py Normal file
View File

@ -0,0 +1,35 @@
import re
class wireless:
def __init__(self, device = "wlan0"):
self.device = device
self.__link = ""
self.__level = ""
self.__noise = ""
def __parse(self):
f = open("/proc/net/wireless", "r")
for line in f:
line = line.strip()
if re.match("^" + self.device + ".*$", line):
line = re.sub("\s+", " ", line)
lst = line.split(" ")
self.__link = lst[2]
self.__level = lst[3]
if re.match(".*\.$", self.__level):
self.__level = re.sub("\.", "", self.__level)
self.__noise = lst[4]
break
f.close()
def level(self):
self.__parse()
return self.__level
def link(self):
self.__parse()
return self.__link
def noise(self):
self.__parse()
return self.__noise