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)