wifi level via mqtt
This commit is contained in:
		
							
								
								
									
										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)
 | 
			
		||||
		Reference in New Issue
	
	Block a user