Publish current background color

This commit is contained in:
Ollo 2021-01-15 19:28:20 +01:00
parent 4e9d78c86a
commit 9763f4b573

View File

@ -10,6 +10,9 @@ function handleSingleCommand(client, topic, data)
briPercent=0
m:publish(mqttPrefix .. "/clock", "OFF", 0, 0)
elseif ((data:sub(1,1) == "#" and data:len() == 7) or (string.match(data, "%d+,%d+,%d+"))) then
local red=0
local green=0
local blue=0
if (data:sub(1,1) == "#") then
red = tonumber(data:sub(2,3), 16)
green = tonumber(data:sub(4,5), 16)
@ -17,8 +20,9 @@ function handleSingleCommand(client, topic, data)
else
red, green, blue = string.match(data, "(%d+),(%d+),(%d+)")
end
colorBg=string.char(green* briPercent / 100, red * briPercent / 100, blue * briPercent / 100)
colorBg=string.char(red* briPercent / 100, green * briPercent / 100, blue * briPercent / 100)
print("Updated BG: " .. tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue) )
m:publish(mqttPrefix .. "/background", tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue), 0, 0)
if (displayTime~= nil) then
displayTime()
end
@ -67,6 +71,10 @@ function registerMqtt()
tmr.alarm(3, 1000, 0, function()
-- publish a message with data = hello, QoS = 0, retain = 0
client:publish(mqttPrefix .. "/ip", tostring(wifi.sta.getip()), 0, 0)
local red = string.byte(colorBg,1)
local green = string.byte(colorBg,2)
local blue = string.byte(colorBg,3)
client:publish(mqttPrefix .. "/background", tostring(red) .. "," .. tostring(green) .. "," .. tostring(blue), 0, 0)
end)
end,
function(client, reason)