Commit 99021435 authored by chrissi^'s avatar chrissi^
Browse files

RgbChannel: Add Class to control RGB channel

Signed-off-by: chrissi^'s avatarChris Fiege <>
parent 5a322be0
......@@ -107,6 +107,37 @@ class OnBoardLed:
def pub(self):
self._mqtt_client.publish(self._topic_get, str(self._state))
class RgbChannel:
def __init__(self, mqtt_client, mqtt_topic, Pin_R, Pin_G, Pin_B):
self._rgb =(0,0,0)
self._on = False
self._topic_on_get = mqtt_topic+"/on/get"
self._topic_on_set = mqtt_topic+"/on/set"
self._topic_rgb_get = mqtt_topic+"/rgb/get"
self._topic_rgb_set = mqtt_topic+"/rgb/set"
self._mqtt_client = mqtt_client
def _cb(self, topic, msg):
if topic == self._topic_on_set:
self._on = "True" if msg == "True" else "False"
return True
elif topic == self._topic_rgb_set:
self._rgb = [int(x) for x in msg.split(",")]
return True
except Exception as e:
print("RgbChannel: Failed to parse value '{}' for topic '{}' with: {}".format(msg, topic, e))
return False
def pub(self):
self._mqtt_client.publish(self._topic_on_get, str(self._on))
self._mqtt_client.publish(self._topic_rgb_get, str(self._rgb))
s = scheduler.Scheduler()
......@@ -126,6 +157,9 @@ s.register(, timeout=5)
led = OnBoardLed(m, "ledctl/{}/OnBoardLed".format(m.machine_id))
s.register(, timeout=5)
str1 = RgbChannel(m, "ledctl/{}/String1".format(m.machine_id), None, None, None)
s.register(, timeout=5)
# start scheduler
# runs forever
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment