Brightness is controllable via MQTT
This commit is contained in:
parent
8858fa19bd
commit
df7f33bbf0
10
mqtt.lua
10
mqtt.lua
@ -7,14 +7,14 @@ function startMqtt()
|
||||
if data ~= nil then
|
||||
print(data)
|
||||
if (data == "ON") then
|
||||
mqttBrightness=100
|
||||
briPercent=100
|
||||
m:publish(mqttPrefix .. "/clock", "ON", 0, 0)
|
||||
elseif (data == "OFF") then
|
||||
mqttBrightness=0
|
||||
briPercent=0
|
||||
m:publish(mqttPrefix .. "/clock", "OFF", 0, 0)
|
||||
else
|
||||
if (tonumber(data) >= 0 and tonumber(data) <= 100) then
|
||||
mqttBrightness=tonumber(data)
|
||||
briPercent=tonumber(data)
|
||||
m:publish(mqttPrefix .. "/clock", tostring(data), 0, 0)
|
||||
end
|
||||
end
|
||||
@ -22,7 +22,7 @@ function startMqtt()
|
||||
end)
|
||||
|
||||
m:connect(mqttServer, 1883, 0, function(client)
|
||||
print("[MQTT] connected")
|
||||
print("MQTT is connected")
|
||||
mqttConnected = true
|
||||
-- subscribe topic with qos = 0
|
||||
client:subscribe(mqttPrefix .. "/command", 0)
|
||||
@ -38,7 +38,7 @@ if (mqttServer ~= nil and mqttPrefix ~= nil) then
|
||||
startMqtt()
|
||||
print "Started MQTT client"
|
||||
|
||||
tmr.alarm(5, 60000, 1 ,function()
|
||||
tmr.alarm(5, 30000, 1 ,function()
|
||||
m:publish(mqttPrefix .. "/brightness", tostring(briPercent), 0, 0)
|
||||
end)
|
||||
end
|
Loading…
Reference in New Issue
Block a user