ich bin langsam schon am Verzweifeln. Ich habe solch ein Matrix-Modul: https://www.reichelt.de/de/de/entwickle ... tlink&&r=1
Angesteuert wird die Matrix über folgende Bibliothek: https://github.com/hzeller/rpi-rgb-led-matrix
Dieses habe ich an einem RaspberryPi 3B+ über einen HAT angeschlossen.
Als Smarthome-Server habe ich ioBroker, dort läuft auch ein mqtt-Broker.
Auf dem Raspberry möchte ich nun einen Wert per mqtt abfragen (klappt auch soweit), um mir dann bestimmte Sachen auf der Martix anzeigen zu lassen.
Das Programm startet, ich gebe "qqq" im Broker ein, der Raspberry empfängt es und schaltet entsprechend die Matrix ein. Ich gebe "aus" im Broker ein, der Raspberry empfängt es und die Matrix zeigt nichts mehr an. Soweit ist alles in Ordnung. Gebe ich aber wieder "qqq" im Broker ein, interessiert das den Raspberry gar nicht. Er empfängt einfach keine Daten mehr. Ich muss das Programm neustarten, dann funktioniert es wieder einmal und dann will er nichts mehr empfangen.
Habe ich hier irgendwo einen Denkfehler?
Code: Alles auswählen
#!/usr/bin/env python
# Display a runtext with double-buffering.
from samplebase import SampleBase
from rgbmatrix import graphics
import paho.mqtt.client as mqtt
from threading import Thread
class Timer(SampleBase):
def __init__(self, *args, **kwargs):
print("Timer erstellt")
super(Timer, self).__init__(*args, **kwargs)
def run(self):
print("in der run --> " + mqttString)
while("qqq" in mqttString):
print("in der while --> " + mqttString)
canvas = self.matrix
font = graphics.Font()
font.LoadFont("/opt/rpi-rgb-led-matrix/fonts/own/timer.bdf")
graphics.DrawText(canvas, font, 0, 32, graphics.Color(0, 0, 255), "25:43")
def timerAn():
print("Timer wird aktiviert")
timer = Timer()
if (not timer.process()):
timer.print_help()
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
client.subscribe("AlexaBildschirm/NeoPixelMatrixDisplayNeu")
def on_message(client, userdata, msg):
global mqttString
global clientMqtt
print(msg.topic + " " + str(msg.payload))
if ("qqq" in msg.payload):
mqttString = "qqq"
print("qqq gefunden --> " + mqttString)
Thread(target=timerAn).start()
elif ("aus" in msg.payload):
mqttString = "aus"
print("Bildschirm aus --> " + mqttString)
clientMqtt = mqtt.Client()
clientMqtt.on_connect = on_connect
clientMqtt.on_message = on_message
clientMqtt.connect("192.168.178.29", 1883, 60)
clientMqtt.loop_forever()
Ich hoffe, ihr könnt mir weiterhelfen, gerne auch komplett andere Ansätze, wenn die besser funktionieren.in der while --> qqq
in der while --> qqq
in der while --> qqq
in der while --> qqq
in der while --> qqq
in der while --> qqq
in der while --> qqq
AlexaBildschirm/NeoPixelMatrixDisplayNeu aus
in der while --> qqq
Bildschirm aus --> aus
Liebe Grüße
Thomas