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:
|
Install the optional packages:
|
||||||
<pre>
|
<pre>
|
||||||
./tools/initialDietFlash.sh /dev/ttyUSB0 mqtt.lua
|
./tools/initialDietFlash.sh /dev/ttyUSB0 mqtt.lua
|
||||||
|
./tools/initialDietFlash.sh /dev/ttyUSB0 mqtt2.lua
|
||||||
./tools/initialDietFlash.sh /dev/ttyUSB0 ds18b20.lua
|
./tools/initialDietFlash.sh /dev/ttyUSB0 ds18b20.lua
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
5
main.lua
5
main.lua
@ -60,11 +60,6 @@ function displayTime()
|
|||||||
local c = dw.countChars(words)
|
local c = dw.countChars(words)
|
||||||
dw.generateLEDs(rgbBuffer, words, colorBg, color, color1, color2, color3, color4, invertRows, c)
|
dw.generateLEDs(rgbBuffer, words, colorBg, color, color1, color2, color3, color4, invertRows, c)
|
||||||
end
|
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
|
dw = nil
|
||||||
collectgarbage()
|
collectgarbage()
|
||||||
|
|
||||||
|
30
mqtt.lua
30
mqtt.lua
@ -1,7 +1,3 @@
|
|||||||
-- Global Variables
|
|
||||||
-- Display other numbers, e.g. Temperatur
|
|
||||||
tw=nil
|
|
||||||
tcol=nil
|
|
||||||
-- Module Variables
|
-- Module Variables
|
||||||
-- Mqtt variable
|
-- Mqtt variable
|
||||||
local mMqttClient=nil
|
local mMqttClient=nil
|
||||||
@ -129,31 +125,6 @@ function registerMqtt()
|
|||||||
print("MQTT " .. topic .. ":" .. data)
|
print("MQTT " .. topic .. ":" .. data)
|
||||||
if (topic == (mqttPrefix .. "/cmd/single")) then
|
if (topic == (mqttPrefix .. "/cmd/single")) then
|
||||||
handleSingleCommand(client, topic, data)
|
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
|
-- Handle here the /cmd/# sublevel
|
||||||
if (string.match(topic, "telnet$")) then
|
if (string.match(topic, "telnet$")) then
|
||||||
@ -190,6 +161,7 @@ function registerMqtt()
|
|||||||
elseif (string.match(topic, "color4$")) then
|
elseif (string.match(topic, "color4$")) then
|
||||||
color4 = parseBgColor(data, "color4")
|
color4 = parseBgColor(data, "color4")
|
||||||
print("Updated color4" )
|
print("Updated color4" )
|
||||||
|
--FIXME load here the mqtt2 file
|
||||||
else
|
else
|
||||||
for i=1,10,1 do
|
for i=1,10,1 do
|
||||||
if (string.match(topic, "row".. tostring(i) .."$")) then
|
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