Move startup procedure into one loop

This commit is contained in:
Ollo
2020-12-08 21:51:14 +01:00
parent 10104b5d0e
commit 7e7a87f90a
2 changed files with 46 additions and 29 deletions

View File

@@ -34,14 +34,17 @@ function startMqtt()
end)
end
if (mqttServer ~= nil and mqttPrefix ~= nil) then
startMqtt()
print "Started MQTT client"
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
function startMqttClient()
if (mqttServer ~= nil and mqttPrefix ~= nil) then
startMqtt()
print "Started MQTT client"
oldBrightness=0
tmr.alarm(5, 10000, 1 ,function()
if (oldBrightness ~= briPercent) then
m:publish(mqttPrefix .. "/brightness", tostring(briPercent), 0, 0)
m:publish(mqttPrefix .. "/heap", tostring(node.heap()), 0, 0)
end
oldBrightness = briPercent
end)
end
end