Created
September 24, 2016 00:04
-
-
Save dmarkey/4ca08075e369b22e8aa339f3ab1347c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how to use?any instruction?