Compare commits

..

No commits in common. "feature/wifi_info" and "master" have entirely different histories.

4 changed files with 1 additions and 74 deletions

23
mqtt.py
View File

@ -1,23 +0,0 @@
#!/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)

View File

@ -1,12 +0,0 @@
#!/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,15 +2,12 @@
import socket import socket
import time import time
import wireless
target = "192.168.178.21" target = "192.168.178.21"
port = 5005 port = 5005
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
w = wireless.wireless("wlan0")
while 1: while 1:
msg = "#WIFI:LEVEL:" + w.level() s.sendto("test", (target, port))
s.sendto(msg, (target, port))
time.sleep(1) time.sleep(1)

View File

@ -1,35 +0,0 @@
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