Only temperature is display; time is killed

This commit is contained in:
Ollo 2021-11-01 13:01:40 +01:00
parent 57de18b37c
commit 5d96adb424
2 changed files with 64 additions and 1 deletions

View File

@ -61,6 +61,13 @@ function displayTime()
local c = dw.countChars(words)
dw.generateLEDs(rgbBuffer, words, colorBg, color, color1, color2, color3, color4, invertRows, c)
end
if (mqttDispTemp ~= nil) then
local tw, tcol = mqttDispTemp(dw, rgbBuffer, invertRows)
if ( (tw ~= nil) and (tcol ~= nil) ) then
local c1 = dw.countChars(tw)
dw.generateLEDs(rgbBuffer, tw, nil, tcol, nil, nil, nil, nil, invertRows, c1)
end
end
dw = nil
collectgarbage()
print("dw: " .. tostring(node.heap()))

View File

@ -3,6 +3,7 @@ local m=nil
local mqttConnected = false
-- Temp:
local t=nil
local dispTemp=10
function handleSingleCommand(client, topic, data)
if (data == "ON") then
@ -105,16 +106,71 @@ function reConnectMqtt()
end
end
-- Logic to display Mqtt
function mqttDispTemp(dw, rgbBuffer, invertRows)
if (dispTemp ~= nil) then
-- Values: it, is, 5 minutes, 10 minutes, afer, before, three hour, quarter, dreiviertel, half, s
-- hours: one, one Long, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve
-- Special ones: twenty, clock, minute 1 flag, minute 2 flag, minute 3 flag, minute 4 flag
local ret = { it=0, is=0, m5=0, m10=0, ha=0, hb=0, h3=0, hq=0, h3q=0, half=0, s=0,
h1=0, h1l=0, h2=0, h3=0, h4=0, h5=0, h6=0, h7=0, h8=0, h9=0, h10=0, h11=0, h12=0,
m20=0, cl=0, m1=0, m2=0, m3=0, m4=0 }
print("Mqtt Display of temperature: " .. tostring(dispTemp) )
if (dispTemp == 1) or (dispTemp == -1) then
ret.h1=1
elseif (dispTemp == 2) or (dispTemp == -2) then
ret.h2=1
elseif (dispTemp == 3) or (dispTemp == -3) then
ret.h3=1
elseif (dispTemp == 4) or (dispTemp == -4) then
ret.h4=1
elseif (dispTemp == 5) or (dispTemp == -5) then
ret.h5=1
elseif (dispTemp == 6) or (dispTemp == -6) then
ret.h6=1
elseif (dispTemp == 7) or (dispTemp == -7) then
ret.h7=1
elseif (dispTemp == 8) or (dispTemp == -8) then
ret.h8=1
elseif (dispTemp == 9) or (dispTemp == -9) then
ret.h9=1
elseif (dispTemp == 10) or (dispTemp == -10) then
ret.h10=1
elseif (dispTemp == 11) or (dispTemp == -11) then
ret.h11=1
elseif (dispTemp == 12) or (dispTemp == -12) then
ret.h12=1
else
-- over or under temperature
end
local col=string.char(128,0,0) -- red; positive degrees
if (dispTemp < 0) then
col=string.char(0,0,128) -- blue; negative degrees
end
return ret, col
else
return nil, nil
end
end
-- MQTT extension
function registerMqtt()
m = mqtt.Client("wordclock", 120)
-- on publish message receive event
m:on("message", function(client, topic, data)
print(topic .. ":" )
print("MQTT " .. topic .. ":" )
if data ~= nil then
print(data)
if (topic == (mqttPrefix .. "/cmd/single")) then
handleSingleCommand(client, topic, data)
elseif (topic == (mqttPrefix .. "/cmd/temp")) then
if ( data == "" ) then
dispTemp = nil
else
dispTemp = tonumber(data)
end
else
-- Handle here the /cmd/# sublevel
if (string.match(topic, "telnet$")) then