aboutsummaryrefslogtreecommitdiff
path: root/bigclown-leds
blob: 9bb3b0b7b57670a76b436c5c2fd25b0549d87dd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3
import paho.mqtt.client as mqtt


def on_connect(client, userdata, flags, rc):
    print("Connected with result code "+str(rc))
    client.subscribe("node/lcd-thermostat:0/led/#")


# The callback for when a PUBLISH message is received from the server.
def on_message(client, userdata, msg):
    topic = msg.topic[26:]
    client.publish(
        'node/power-controller:0/led-strip/-/' + topic,
        payload=msg.payload)


#def on_log(mqttc, obj, level, string):
#    print(string)


def main():
    client = mqtt.Client()
    client.on_connect = on_connect
    client.on_message = on_message
    #client.on_log = on_log

    client.connect("127.0.0.1", 1883, 60)
    client.loop_forever()


if __name__ == '__main__':
    main()