wifi level via mqtt

This commit is contained in:
tkl 2016-08-14 09:27:33 +00:00
parent 8f80e3f1a8
commit 2791190503

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)