blob: 2871d523db34eb602a7e4fd174a0b09f1e9be9c6 (
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
|
#!/usr/bin/env python3
import paho.mqtt.client as mqtt
def on_connect(client, userdata, 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 main():
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("127.0.0.1", 1883, 60)
client.loop_forever()
if __name__ == '__main__':
main()
|