Seperated new logic into a new mqtt file
This commit is contained in:
parent
158f989c53
commit
a4893cc411
@ -25,6 +25,7 @@ Then disconnect the serial terminal and copy the required files to the microcont
|
||||
Install the optional packages:
|
||||
<pre>
|
||||
./tools/initialDietFlash.sh /dev/ttyUSB0 mqtt.lua
|
||||
./tools/initialDietFlash.sh /dev/ttyUSB0 mqtt2.lua
|
||||
./tools/initialDietFlash.sh /dev/ttyUSB0 ds18b20.lua
|
||||
</pre>
|
||||
|
||||
|
5
main.lua
5
main.lua
@ -60,11 +60,6 @@ function displayTime()
|
||||
local c = dw.countChars(words)
|
||||
dw.generateLEDs(rgbBuffer, words, colorBg, color, color1, color2, color3, color4, invertRows, c)
|
||||
end
|
||||
if ( (tw ~= nil) and (tcol ~= nil) ) then
|
||||
local c1 = dw.countChars(tw)
|
||||
dw.generateLEDs(rgbBuffer, tw, nil, tcol, nil, nil, nil, nil, invertRows, c1)
|
||||
print("Show number")
|
||||
end
|
||||
dw = nil
|
||||
collectgarbage()
|
||||
|
||||
|
32
mqtt.lua
32
mqtt.lua
@ -1,7 +1,3 @@
|
||||
-- Global Variables
|
||||
-- Display other numbers, e.g. Temperatur
|
||||
tw=nil
|
||||
tcol=nil
|
||||
-- Module Variables
|
||||
-- Mqtt variable
|
||||
local mMqttClient=nil
|
||||
@ -129,32 +125,7 @@ function registerMqtt()
|
||||
print("MQTT " .. topic .. ":" .. data)
|
||||
if (topic == (mqttPrefix .. "/cmd/single")) then
|
||||
handleSingleCommand(client, topic, data)
|
||||
elseif (topic == (mqttPrefix .. "/cmd/num/val")) then
|
||||
if (( data == "" ) or (data == nil)) then
|
||||
tw=nil
|
||||
print("MQTT | wordclock failed")
|
||||
else
|
||||
-- generate the temperatur to display, once as it will not change
|
||||
local dispTemp = tonumber(data)
|
||||
collectgarbage()
|
||||
mydofile("wordclock")
|
||||
if (wc ~= nil) then
|
||||
tw = wc.showText(dw, rgbBuffer, invertRows, dispTemp)
|
||||
wc = nil
|
||||
print("MQTT | generated words for: " .. tostring(dispTemp))
|
||||
else
|
||||
print("MQTT | wordclock failed")
|
||||
end
|
||||
end
|
||||
elseif (topic == (mqttPrefix .. "/cmd/num/col")) then
|
||||
-- Set number of the color to display
|
||||
if (( data ~= "" ) and (data ~= nil)) then
|
||||
tcol = parseBgColor(data, "num/col")
|
||||
else
|
||||
tcol = nil
|
||||
print("MQTT | Hide number")
|
||||
end
|
||||
else
|
||||
else
|
||||
-- Handle here the /cmd/# sublevel
|
||||
if (string.match(topic, "telnet$")) then
|
||||
client:publish(mqttPrefix .. "/telnet", tostring(wifi.sta.getip()), 0, 0)
|
||||
@ -190,6 +161,7 @@ function registerMqtt()
|
||||
elseif (string.match(topic, "color4$")) then
|
||||
color4 = parseBgColor(data, "color4")
|
||||
print("Updated color4" )
|
||||
--FIXME load here the mqtt2 file
|
||||
else
|
||||
for i=1,10,1 do
|
||||
if (string.match(topic, "row".. tostring(i) .."$")) then
|
||||
|
34
mqtt2.lua
Normal file
34
mqtt2.lua
Normal file
@ -0,0 +1,34 @@
|
||||
-- Global Variables
|
||||
-- Display other numbers, e.g. Temperatur
|
||||
tw=nil
|
||||
tcol=nil
|
||||
|
||||
function parseMqttSub(client, topic, data)
|
||||
|
||||
if (topic == (mqttPrefix .. "/cmd/num/val")) then
|
||||
if (( data == "" ) or (data == nil)) then
|
||||
tw=nil
|
||||
print("MQTT | wordclock failed")
|
||||
else
|
||||
-- generate the temperatur to display, once as it will not change
|
||||
local dispTemp = tonumber(data)
|
||||
collectgarbage()
|
||||
mydofile("wordclock")
|
||||
if (wc ~= nil) then
|
||||
tw = wc.showText(dw, rgbBuffer, invertRows, dispTemp)
|
||||
wc = nil
|
||||
print("MQTT | generated words for: " .. tostring(dispTemp))
|
||||
else
|
||||
print("MQTT | wordclock failed")
|
||||
end
|
||||
end
|
||||
elseif (topic == (mqttPrefix .. "/cmd/num/col")) then
|
||||
-- Set number of the color to display
|
||||
if (( data ~= "" ) and (data ~= nil)) then
|
||||
tcol = parseBgColor(data, "num/col")
|
||||
else
|
||||
tcol = nil
|
||||
print("MQTT | Hide number")
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user