mqtt-to-flipdot/mqtt-to-flipdot.py

40 lines
1.0 KiB
Python

#!/usr/bin/env python3
import time
import paho.mqtt.client as mqtt
from FlipdotSender import FlipdotSender
import time
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
client.subscribe("raum2/flipdot/text")
client.subscribe("raum2/flipdot/scroll")
def on_message(client, userdata, msg):
print(msg.topic + " " + str(msg.payload.decode("utf-8")))
if msg.topic == "raum2/flipdot/scroll":
payload = msg.payload.decode("utf-8")
speed = int(payload[0])
flipdot.send_marquee(payload[1:], speed)
if msg.topic == "raum2/flipdot/text":
payload = msg.payload.decode("utf-8")
flipdot.send_text(payload)
flipdot = FlipdotSender("2001:67c:275c:a9::c", 2323)
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("raum.ctdo.de", 1883, 60)
client.loop_start()
while True:
time.sleep(2)