diff --git a/Readme.md b/Readme.md index 0d8df53..bb2087d 100644 --- a/Readme.md +++ b/Readme.md @@ -25,6 +25,7 @@ Then disconnect the serial terminal and copy the required files to the microcont Install the optional packages:
 ./tools/initialDietFlash.sh /dev/ttyUSB0 mqtt.lua
+./tools/initialDietFlash.sh /dev/ttyUSB0 mqtt2.lua
 ./tools/initialDietFlash.sh /dev/ttyUSB0 ds18b20.lua
 
diff --git a/main.lua b/main.lua index 4fd5e04..b4489d9 100644 --- a/main.lua +++ b/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() diff --git a/mqtt.lua b/mqtt.lua index 3b3a73c..74cca5a 100644 --- a/mqtt.lua +++ b/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 diff --git a/mqtt2.lua b/mqtt2.lua new file mode 100644 index 0000000..4bffd6c --- /dev/null +++ b/mqtt2.lua @@ -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