diff --git a/main.lua b/main.lua index 1260ff7..6d10fd7 100644 --- a/main.lua +++ b/main.lua @@ -54,6 +54,9 @@ function displayTime() local words = display_timestat(time.hour, time.minute) if ((dim ~= nil) and (dim == "on")) then words.briPercent=briPercent + if (words.briPercent ~= nil and words.briPercent < 3) then + words.briPercent=3 + end else words.briPercent=nil end @@ -164,7 +167,7 @@ function normalOperation() end end) -- Start the time Thread - tmr.alarm(1, 10000, 1 ,function() + tmr.alarm(1, 5000, 1 ,function() displayTime() collectgarbage() end) diff --git a/mqtt.lua b/mqtt.lua index 67e0356..8f51f35 100644 --- a/mqtt.lua +++ b/mqtt.lua @@ -9,13 +9,16 @@ function startMqtt() if (data == "ON") then briPercent=100 m:publish(mqttPrefix .. "/clock", "ON", 0, 0) + displayTime() elseif (data == "OFF") then briPercent=0 m:publish(mqttPrefix .. "/clock", "OFF", 0, 0) + displayTime() else if (tonumber(data) >= 0 and tonumber(data) <= 100) then briPercent=tonumber(data) m:publish(mqttPrefix .. "/clock", tostring(data), 0, 0) + displayTime() end end end @@ -37,8 +40,11 @@ end if (mqttServer ~= nil and mqttPrefix ~= nil) then startMqtt() print "Started MQTT client" - - tmr.alarm(5, 30000, 1 ,function() + oldBrightness=0 + tmr.alarm(5, 10000, 1 ,function() + if (oldBrightness <> briPercent) then m:publish(mqttPrefix .. "/brightness", tostring(briPercent), 0, 0) + end + oldBrightness = briPercent end) -end \ No newline at end of file +end