Skip to content

Instantly share code, notes, and snippets.

@dmarkey
Created September 24, 2016 00:04
Show Gist options
  • Save dmarkey/4ca08075e369b22e8aa339f3ab1347c7 to your computer and use it in GitHub Desktop.
Save dmarkey/4ca08075e369b22e8aa339f3ab1347c7 to your computer and use it in GitHub Desktop.
import simple as umqtt
SERVER="dmarkey.com"
PORT=1883
CLIENT_ID="asafsd"
RELAY="/sys/class/leds/tp-link:blue:relay/brightness"
SET = "/home/switches/homeswitch1/set"
STATUS = "/home/switches/homeswitch1"
client = umqtt.MQTTClient(CLIENT_ID, SERVER, PORT)
def callback(topic, data):
if data == b'1':
open(RELAY, "w").write('1')
client.publish(STATUS,'1', retain=True)
else:
open(RELAY, "w").write('0')
client.publish(STATUS,'0', retain=True)
client.connect()
client.set_callback(callback)
client.subscribe(SET)
while True:
client.wait_msg()
@kornfool
Copy link

how to use?any instruction?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment