aboutsummaryrefslogtreecommitdiff
path: root/bigclown-leds
blob: 516515ef92292c613cfd3e63d2018e7fbbd7e91c (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
34
35
36
37
38
39
40
#!/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("bigclown/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:]
    if topic == "effect/set":
        # Well for now just this way
        client.publish(
            "bigclown/node/power-controller:0/led-strip/-/effect/set",
            '{"type": "rainbow", "wait":50}',
        )
    else:
        client.publish(
            "bigclown/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()