#!/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") if (payload[0]).isdigit(): speed = int(payload[0]) text = payload[1:] else: speed = 3 text = payload flipdot.send_marquee(text, 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)