From 2791190503de1d6e71c8c44cb8255c97d8150671 Mon Sep 17 00:00:00 2001 From: tkl Date: Sun, 14 Aug 2016 09:27:33 +0000 Subject: [PATCH] wifi level via mqtt --- mqtt.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 mqtt.py diff --git a/mqtt.py b/mqtt.py new file mode 100755 index 0000000..d69d2c1 --- /dev/null +++ b/mqtt.py @@ -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)