Measure temperature every minute
This commit is contained in:
parent
7f6c9689ea
commit
a98a30c06b
12
mqtt.lua
12
mqtt.lua
@ -224,6 +224,7 @@ function startMqttClient()
|
|||||||
local loldBrightness=0
|
local loldBrightness=0
|
||||||
mOldTemp=0
|
mOldTemp=0
|
||||||
local lMqttTimer = tmr.create()
|
local lMqttTimer = tmr.create()
|
||||||
|
local tempCounter=0
|
||||||
-- Check every 12 seconds
|
-- Check every 12 seconds
|
||||||
lMqttTimer:register(12321, tmr.ALARM_AUTO, function (kTemp)
|
lMqttTimer:register(12321, tmr.ALARM_AUTO, function (kTemp)
|
||||||
if (mMqttConnected) then
|
if (mMqttConnected) then
|
||||||
@ -236,7 +237,7 @@ function startMqttClient()
|
|||||||
mMqttClient:publish(mqttPrefix .. "/brightness", tostring(briPer), 0, 0)
|
mMqttClient:publish(mqttPrefix .. "/brightness", tostring(briPer), 0, 0)
|
||||||
loldBrightness = briPer
|
loldBrightness = briPer
|
||||||
else
|
else
|
||||||
if ((t ~= nil) and (heapusage > 12000)) then
|
if ((t ~= nil) and (heapusage > 11900) and (tempCounter > 10)) then
|
||||||
local ds18b20=require("ds18b20_diet")
|
local ds18b20=require("ds18b20_diet")
|
||||||
ds18b20.setup(2) -- GPIO4
|
ds18b20.setup(2) -- GPIO4
|
||||||
readTemp(ds18b20) -- read once, to setup chip
|
readTemp(ds18b20) -- read once, to setup chip
|
||||||
@ -245,14 +246,17 @@ function startMqttClient()
|
|||||||
temperatur=nil
|
temperatur=nil
|
||||||
end
|
end
|
||||||
ds18b20=nil
|
ds18b20=nil
|
||||||
else
|
tempCounter = 0
|
||||||
collectgarbage()
|
else
|
||||||
end
|
tempCounter = tempCounter + 1
|
||||||
|
end
|
||||||
|
collectgarbage()
|
||||||
if (temperatur ~= nil and temperatur ~= mOldTemp) then
|
if (temperatur ~= nil and temperatur ~= mOldTemp) then
|
||||||
mOldTemp = temperatur
|
mOldTemp = temperatur
|
||||||
mMqttClient:publish(mqttPrefix .. "/temp", tostring(temperatur/100)..".".. tostring(temperatur%100), 0, 0)
|
mMqttClient:publish(mqttPrefix .. "/temp", tostring(temperatur/100)..".".. tostring(temperatur%100), 0, 0)
|
||||||
else
|
else
|
||||||
mMqttClient:publish(mqttPrefix .. "/heap", tostring(heapusage), 0, 0)
|
mMqttClient:publish(mqttPrefix .. "/heap", tostring(heapusage), 0, 0)
|
||||||
|
collectgarbage()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
heapusage=nil
|
heapusage=nil
|
||||||
|
Loading…
Reference in New Issue
Block a user