All colors can be changed via MQTT

This commit is contained in:
Ollo 2021-04-03 13:15:37 +02:00
parent 23bcd36a34
commit 8b58d4a39f
2 changed files with 42 additions and 6 deletions

View File

@ -42,7 +42,8 @@ Mandatory:
* GPIO2 LEDs * GPIO2 LEDs
* GPIO0 Bootloader (at start) * GPIO0 Bootloader (at start)
* GPIO0 factory reset (long during operation) * GPIO0 factory reset (long during operation)
Optinal:
Optional:
* ADC VT93N2, 48k light resistor * ADC VT93N2, 48k light resistor
* GPIO4 DS18B20 Temperatur sensor * GPIO4 DS18B20 Temperatur sensor
@ -50,6 +51,11 @@ Optinal:
### Status ### Status
* **basetopic**/brightness **Current brightness in percent** * **basetopic**/brightness **Current brightness in percent**
* **basetopic**/background **Current background color** * **basetopic**/background **Current background color**
* **basetopic**/color **Current foreground color**
* **basetopic**/color1 **Current foreground color for first minute**
* **basetopic**/color2 **Current foreground color for second minute**
* **basetopic**/color3 **Current foreground color for third minute**
* **basetopic**/color4 **Current foreground color for fourth minute**
* **basetopic**/row1 **Current background color** * **basetopic**/row1 **Current background color**
* **basetopic**/temp **Temperatur** * **basetopic**/temp **Temperatur**
@ -60,8 +66,18 @@ Optinal:
* 0-100 **Set brightness to given value** * 0-100 **Set brightness to given value**
* #rrggbb **Background color is set to hex representation of red, green and blue** * #rrggbb **Background color is set to hex representation of red, green and blue**
* 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue** * 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue**
* **basetopic**/cmd/color
* 0-255,0-255,0-255 **Foreground color is set to decimal representation of red, green an blue**
* **basetopic**/cmd/color1
* 0-255,0-255,0-255 **Foreground color for first minute is set to decimal representation of red, green an blue**
* **basetopic**/cmd/color2
* 0-255,0-255,0-255 **Foreground color for second minute is set to decimal representation of red, green an blue**
* **basetopic**/cmd/color3
* 0-255,0-255,0-255 **Foreground color for third minute is set to decimal representation of red, green an blue**
* **basetopic**/cmd/color4
* 0-255,0-255,0-255 **Foreground color for fourth minute is set to decimal representation of red, green an blue**
* **basetopic**/cmd/telnet * **basetopic**/cmd/telnet
* ignored **Stop MQTT server and start telnetserver at port 23** * ignored **Stop MQTT server, clock and start telnetserver at port 23**
* **basetopic**/cmd/row1 * **basetopic**/cmd/row1
* 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue** * 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue**
* **basetopic**/cmd/row1 * **basetopic**/cmd/row1

View File

@ -39,7 +39,8 @@ end
-- Parse MQTT data and extract color -- Parse MQTT data and extract color
-- @param data MQTT information -- @param data MQTT information
-- @param row string of the row e.g. "row1" used to publish current state -- @param row string of the row e.g. "row1" used to publish current state
function parseBgColor(data, row) -- @param per percent the color should be dimmed
function parseBgColor(data, row, per)
local red=nil local red=nil
local green=nil local green=nil
local blue=nil local blue=nil
@ -52,7 +53,11 @@ function parseBgColor(data, row)
end end
if ((red ~= nil) and (green ~= nil) and (blue ~= nil) ) then if ((red ~= nil) and (green ~= nil) and (blue ~= nil) ) then
m:publish(mqttPrefix .. "/"..row, tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue), 0, 0) m:publish(mqttPrefix .. "/"..row, tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue), 0, 0)
return string.char(green * briPer / 100, red * briPer / 100, blue * briPer / 100) if (per ~= nil) then
return string.char(green * per / 100, red * per / 100, blue * per / 100)
else
return string.char(green , red , blue )
end
else else
return nil return nil
end end
@ -104,10 +109,25 @@ function registerMqtt()
else else
print("Cannost start Telnet Server!") print("Cannost start Telnet Server!")
end end
elseif (string.match(topic, "color$")) then
color = parseBgColor(data, "color")
print("Updated color" .. tostring(i) )
elseif (string.match(topic, "color1$")) then
color1 = parseBgColor(data, "color1")
print("Updated color1" .. tostring(i) )
elseif (string.match(topic, "color2$")) then
color = parseBgColor(data, "color2")
print("Updated color2" .. tostring(i) )
elseif (string.match(topic, "color3$")) then
color = parseBgColor(data, "color3")
print("Updated color3" .. tostring(i) )
elseif (string.match(topic, "color4$")) then
color = parseBgColor(data, "color4")
print("Updated color4" .. tostring(i) )
else else
for i=1,10,1 do for i=1,10,1 do
if (string.match(topic, "row".. tostring(i) .."$")) then if (string.match(topic, "row".. tostring(i) .."$")) then
rowbgColor[i] = parseBgColor(data, "row" .. tostring(i)) rowbgColor[i] = parseBgColor(data, "row" .. tostring(i), briPer)
print("Updated row" .. tostring(i) ) print("Updated row" .. tostring(i) )
return return
end end