Compare commits
3 Commits
master
...
2791190503
Author | SHA1 | Date | |
---|---|---|---|
2791190503 | |||
8f80e3f1a8 | |||
d105436a13 |
23
mqtt.py
Executable file
23
mqtt.py
Executable 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
12
test_wireless.py
Executable 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)
|
@ -2,12 +2,15 @@
|
|||||||
|
|
||||||
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:
|
||||||
s.sendto("test", (target, port))
|
msg = "#WIFI:LEVEL:" + w.level()
|
||||||
|
s.sendto(msg, (target, port))
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
35
wireless.py
Normal file
35
wireless.py
Normal 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
|
Loading…
Reference in New Issue
Block a user