Each rows background can be set

This commit is contained in:
Ollo 2021-01-23 19:17:30 +01:00
parent 999c8ae3ac
commit 93b889f706
6 changed files with 258 additions and 200 deletions

View File

@ -56,6 +56,16 @@ Optinal:
* ignored **Stop MQTT server and start telnetserver at port 23**
* **basetopic**/cmd/row1
* 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue**
* **basetopic**/cmd/row1
* 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue**
* **basetopic**/cmd/row2
* 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue**
* **basetopic**/cmd/row3
* 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue**
* For all rows...
* **basetopic**/cmd/row10
* 0-255,0-255,0-255 **Background color is set to decimal representation of red, green an blue**
## OpenHAB2
Tested MQTT with binding-mqtt 2.5.x

186
commands.lua Normal file
View File

@ -0,0 +1,186 @@
function storeConfig(_ssid, _password, _timezoneoffset, _sntpserver, _inv46, _dim, _fcolor, _colorMin1, _colorMin2, _colorMin3, _colorMin4, _bcolor, _threequater)
if ( (_ssid == nil) and
(_password == nil) and
(_timezoneoffset == nil) and
(_sntpserver == nil) and
(_inv46 == nil) and
(_dim == nil) and
(_fcolor == nil) and
(_colorMin1 == nil) and
(_colorMin2 == nil) and
(_colorMin3 == nil) and
(_colorMin4 == nil) and
(_bcolor == nil) and
(_threequater == nil) ) then
print("one parameter is mandatory:")
print("storeConfig(ssid, ")
print(" password,")
print(" timezoneoffset,")
print(" sntpserver,")
print(" inv46,")
print(" dim,")
print(" fcolor,")
print(" colorMin1,")
print(" colorMin2,")
print(" colorMin3,")
print(" colorMin4,")
print(" bcolor,")
print(" threequater)")
print(" ")
print("e.g.:")
print('storeConfig(nil, nil, 1, nil, "on", true, "00FF00", "00FF88", "008888", "00FF44", "004488", "000000", true)')
return
end
if (_password==nil) then
_, password, _, _ = wifi.sta.getconfig()
print("Restore password")
else
password = _password
end
if (_ssid==nil) then
ssid, _, _, _ = wifi.sta.getconfig()
else
ssid = _ssid
end
if (_sntpserver == nil) then
sntpserver = sntpserverhostname
print("Restore SNTP: " .. tostring(sntpserver))
else
sntpserver = _sntpserver
end
if (_timezoneoffset ~= nil) then
timezoneoffset = _timezoneoffset
end
if (_inv46 ~= nil) then
if ((_inv46 == true) or (_inv == "on")) then
inv46 = "on"
elseif ((_inv46 == false) or (_inv == "off")) then
inv46 = "off"
else
inv46 = "off"
end
end
if ( _dim ~= nil) then
dim = _dim
end
if (_fcolor ~= nil) then
fcolor = _fcolor
end
if (_bcolor ~= nil) then
bcolor = _bcolor
end
if (_colorMin1 ~= nil) then
colorMin1 = _colorMin1
end
if (_colorMin2 ~= nil) then
colorMin2 = _colorMin2
end
if (_colorMin3 ~= nil) then
colorMin3 = _colorMin3
end
if (_colorMin4 ~= nil) then
colorMin4 = _colorMin4
end
if (_threequater ~= nil) then
threequater = _threequater
end
print("SSID = " .. tostring(ssid))
print("TZNE = " .. tostring(timezoneoffset))
print("NTP = " .. tostring(sntpserver))
print("INVT = " .. tostring(inv46))
print("DIM = " .. tostring(dim))
print("FCOL = " .. tostring(fcolor))
print("BCOL = " .. tostring(bcolor))
print("MIN1 = " .. tostring(colorMin1))
print("MIN2 = " .. tostring(colorMin2))
print("MIN3 = " .. tostring(colorMin3))
print("MIN4 = " .. tostring(colorMin4))
print("3QRT = " .. tostring(threequater))
local configFile="config.lua"
-- Safe configuration:
file.remove(configFile .. ".new")
sec, _ = rtctime.get()
file.open(configFile.. ".new", "w+")
file.write("-- Config\n" .. "station_cfg={}\nstation_cfg.ssid=\"" .. ssid .. "\"\nstation_cfg.pwd=\"" .. password .. "\"\nstation_cfg.save=false\nwifi.sta.config(station_cfg)\n")
file.write("sntpserverhostname=\"" .. sntpserver .. "\"\n" .. "timezoneoffset=\"" .. timezoneoffset .. "\"\n".. "inv46=\"" .. tostring(inv46) .. "\"\n" .. "dim=\"" .. tostring(dim) .. "\"\n")
if (fcolor ~= nil) then
local hexColor=string.sub(fcolor, 1)
local red = tonumber(string.sub(hexColor, 1, 2), 16)
local green = tonumber(string.sub(hexColor, 3, 4), 16)
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
file.write("color=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
-- fill the current values
color=string.char(green, red, blue)
end
if (colorMin1 ~= nil) then
local hexColor=string.sub(colorMin1, 1)
local red = tonumber(string.sub(hexColor, 1, 2), 16)
local green = tonumber(string.sub(hexColor, 3, 4), 16)
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
file.write("color1=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
color1=string.char(green, red, blue)
end
if ( colorMin2 ~= nil) then
local hexColor=string.sub(colorMin2, 1)
local red = tonumber(string.sub(hexColor, 1, 2), 16)
local green = tonumber(string.sub(hexColor, 3, 4), 16)
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
file.write("color2=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
color2=string.char(green, red, blue)
end
if ( colorMin3 ~= nil) then
local hexColor=string.sub(colorMin3, 1)
local red = tonumber(string.sub(hexColor, 1, 2), 16)
local green = tonumber(string.sub(hexColor, 3, 4), 16)
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
file.write("color3=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
color3=string.char(green, red, blue)
end
if ( colorMin4 ~= nil) then
local hexColor=string.sub(colorMin4, 1)
local red = tonumber(string.sub(hexColor, 1, 2), 16)
local green = tonumber(string.sub(hexColor, 3, 4), 16)
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
file.write("color4=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
color4=string.char(green, red, blue)
end
if ( bcolor ~= nil) then
local hexColor=string.sub(bcolor, 1)
local red = tonumber(string.sub(hexColor, 1, 2), 16)
local green = tonumber(string.sub(hexColor, 3, 4), 16)
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
file.write("colorBg=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
-- fill the current values
colorBg=string.char(green, red, blue)
end
if (getTime ~= nil) then
time = getTime(sec, timezoneoffset)
file.write("print(\"Config from " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. "\")\n")
end
if ( threequater ~= nil) then
file.write("threequater=true\n")
-- fill the current values
threequater=true
else
file.write("threequater=nil\n") -- unset threequater
-- fill the current values
threequater=nil
end
file.close()
collectgarbage()
sec=nil
file.remove(configFile)
if (file.rename(configFile .. ".new", configFile)) then
print("Rename Successfully")
else
print("Cannot rename " .. configFile .. ".new")
end
end

View File

@ -54,7 +54,7 @@ end
local data={}
-- Module displaying of the words
local generateLEDs = function(words, colorBg, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars, row1bgColor)
local generateLEDs = function(words, colorBg, colorFg, colorMin1, colorMin2, colorMin3, colorMin4, invertRows, amountOfChars)
-- Set the local variables needed for the colored progress bar
if (words == nil) then
return nil
@ -118,8 +118,8 @@ local generateLEDs = function(words, colorBg, colorFg, colorMin1, colorMin2, col
local buf=data.colorFg
local line=space
-- line 1----------------------------------------------
if (row1bgColor ~= nil) then
space = row1bgColor
if (rowbgColor[1] ~= nil) then
space = rowbgColor[1]
end
if (words.it==1) then
buf=drawLEDs(data,2) -- ES
@ -141,8 +141,8 @@ if (words.fiveMin== 1) then
buf= buf .. space:rep(4)
end
-- line 2-- even row (so inverted) --------------------
if (row2bgColor ~= nil) then
space = row2bgColor
if (rowbgColor[2] ~= nil) then
space = rowbgColor[2]
else
space = colorBg
end
@ -162,6 +162,11 @@ if (words.fiveMin== 1) then
end
-- line3----------------------------------------------
if (rowbgColor[3] ~= nil) then
space = rowbgColor[3]
else
space = colorBg
end
if (words.threequater == 1) then
line= drawLEDs(data,11) -- Dreiviertel
elseif (words.quater == 1) then
@ -173,6 +178,11 @@ if (words.fiveMin== 1) then
-- fill, the buffer
buf = buf .. line
--line 4-------- even row (so inverted) -------------
if (rowbgColor[4] ~= nil) then
space = rowbgColor[4]
else
space = colorBg
end
if (words.after == 1) then
line= space:rep(2) -- TG
line= line .. drawLEDs(data,4) -- NACH
@ -193,6 +203,11 @@ if (words.fiveMin== 1) then
end
end
------------------------------------------------
if (rowbgColor[5] ~= nil) then
space = rowbgColor[5]
else
space = colorBg
end
if (words.half == 1) then
line= drawLEDs(data,4) -- HALB
line= line .. space:rep(1) -- X
@ -213,6 +228,11 @@ if (words.fiveMin== 1) then
buf=buf .. line
end
------------even row (so inverted) ---------------------
if (rowbgColor[6] ~= nil) then
space = rowbgColor[6]
else
space = colorBg
end
if (words.seven == 1) then
line= space:rep(5)
line= line .. drawLEDs(data,6) -- SIEBEN
@ -238,6 +258,11 @@ if (words.fiveMin== 1) then
end
end
------------------------------------------------
if (rowbgColor[7] ~= nil) then
space = rowbgColor[7]
else
space = colorBg
end
if (words.three == 1) then
line= space:rep(1)
line= line .. drawLEDs(data,4) -- DREI
@ -250,6 +275,11 @@ if (words.fiveMin== 1) then
end
buf = buf .. line
------------even row (so inverted) ---------------------
if (rowbgColor[8] ~= nil) then
space = rowbgColor[8]
else
space = colorBg
end
if (words.four == 1) then
line= space:rep(7)
line= line .. drawLEDs(data,4) -- VIER
@ -268,6 +298,11 @@ if (words.fiveMin== 1) then
buf = buf .. line:sub((11-i)*3-2,(11-i)*3)
end
------------------------------------------------
if (rowbgColor[9] ~= nil) then
space = rowbgColor[9]
else
space = colorBg
end
if (words.eight == 1) then
line= space:rep(1)
line= line .. drawLEDs(data,4) -- ACHT
@ -281,6 +316,11 @@ if (words.fiveMin== 1) then
end
buf = buf .. line
------------even row (so inverted) ---------------------
if (rowbgColor[10] ~= nil) then
space = rowbgColor[10]
else
space = colorBg
end
if (words.six == 1) then
line= space:rep(1)
line= line .. drawLEDs(data,5) -- SECHS

View File

@ -72,8 +72,7 @@ function displayTime()
invertRows=true
end
local characters = displayword.countChars(words)
ledBuf = displayword.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, characters,
row1bgColor)
ledBuf = displayword.generateLEDs(words, colorBg, color, color1, color2, color3, color4, invertRows, characters)
end
displayword = nil
if (ledBuf ~= nil) then

View File

@ -3,6 +3,7 @@ m=nil
mqttConnected = false
-- Temp:
t=nil
rowbgColor= {}
function handleSingleCommand(client, topic, data)
if (data == "ON") then
@ -90,18 +91,26 @@ function registerMqtt()
-- Handle here the /cmd/# sublevel
if (string.match(topic, "telnet$")) then
client:publish(mqttPrefix .. "/telnet", tostring(wifi.sta.getip()), 0, 0)
print("Stop Mqtt")
ws2812.write(string.char(0,0,0):rep(114))
print("Stop Mqtt and Temp")
m=nil
t=nil
mqttConnected = false
stopWordclock()
for i=0,6,1 do tmr.stop(i) end
collectgarbage()
mydofile("telnet")
if (startTelnetServer ~= nil) then
startTelnetServer()
end
elseif (string.match(topic, "row1$")) then
row1bgColor = parseBgColor(data, "row1")
end
else
for i=1,10,1 do
if (string.match(topic, "row".. tostring(i) .."$")) then
rowbgColor[i] = parseBgColor(data, "row" .. tostring(i))
print("Updated row" .. tostring(i) )
return
end
end
end
end
end
end)

View File

@ -28,195 +28,9 @@ function startTelnetServer()
end
end)
print("Welcome to the Wordclock.")
print("- mydofile(\"commands\")")
print("- storeConfig()")
print("Visite https://github.com/nodemcu/nodemcu-firmware/wiki/nodemcu_api_en for further commands")
end)
print("Telnetserver is up")
end
function storeConfig(_ssid, _password, _timezoneoffset, _sntpserver, _inv46, _dim, _fcolor, _colorMin1, _colorMin2, _colorMin3, _colorMin4, _bcolor, _threequater)
if ( (_ssid == nil) and
(_password == nil) and
(_timezoneoffset == nil) and
(_sntpserver == nil) and
(_inv46 == nil) and
(_dim == nil) and
(_fcolor == nil) and
(_colorMin1 == nil) and
(_colorMin2 == nil) and
(_colorMin3 == nil) and
(_colorMin4 == nil) and
(_bcolor == nil) and
(_threequater == nil) ) then
print("one parameter is mandatory:")
print("storeConfig(ssid, ")
print(" password,")
print(" timezoneoffset,")
print(" sntpserver,")
print(" inv46,")
print(" dim,")
print(" fcolor,")
print(" colorMin1,")
print(" colorMin2,")
print(" colorMin3,")
print(" colorMin4,")
print(" bcolor,")
print(" threequater)")
print(" ")
print("e.g.:")
print('storeConfig(nil, nil, 1, nil, "on", true, "00FF00", "00FF88", "008888", "00FF44", "004488", "000000", true)')
return
end
if (_password==nil) then
_, password, _, _ = wifi.sta.getconfig()
print("Restore password")
else
password = _password
end
if (_ssid==nil) then
ssid, _, _, _ = wifi.sta.getconfig()
else
ssid = _ssid
end
if (_sntpserver == nil) then
sntpserver = sntpserverhostname
print("Restore SNTP: " .. tostring(sntpserver))
else
sntpserver = _sntpserver
end
if (_timezoneoffset ~= nil) then
timezoneoffset = _timezoneoffset
end
if (_inv46 ~= nil) then
if ((_inv46 == true) or (_inv == "on")) then
inv46 = "on"
elseif ((_inv46 == false) or (_inv == "off")) then
inv46 = "off"
else
inv46 = "off"
end
end
if ( _dim ~= nil) then
dim = _dim
end
if (_fcolor ~= nil) then
fcolor = _fcolor
end
if (_bcolor ~= nil) then
bcolor = _bcolor
end
if (_colorMin1 ~= nil) then
colorMin1 = _colorMin1
end
if (_colorMin2 ~= nil) then
colorMin2 = _colorMin2
end
if (_colorMin3 ~= nil) then
colorMin3 = _colorMin3
end
if (_colorMin4 ~= nil) then
colorMin4 = _colorMin4
end
if (_threequater ~= nil) then
threequater = _threequater
end
print("SSID = " .. tostring(ssid))
print("TZNE = " .. tostring(timezoneoffset))
print("NTP = " .. tostring(sntpserver))
print("INVT = " .. tostring(inv46))
print("DIM = " .. tostring(dim))
print("FCOL = " .. tostring(fcolor))
print("BCOL = " .. tostring(bcolor))
print("MIN1 = " .. tostring(colorMin1))
print("MIN2 = " .. tostring(colorMin2))
print("MIN3 = " .. tostring(colorMin3))
print("MIN4 = " .. tostring(colorMin4))
print("3QRT = " .. tostring(threequater))
local configFile="config.lua"
-- Safe configuration:
file.remove(configFile .. ".new")
sec, _ = rtctime.get()
file.open(configFile.. ".new", "w+")
file.write("-- Config\n" .. "station_cfg={}\nstation_cfg.ssid=\"" .. ssid .. "\"\nstation_cfg.pwd=\"" .. password .. "\"\nstation_cfg.save=false\nwifi.sta.config(station_cfg)\n")
file.write("sntpserverhostname=\"" .. sntpserver .. "\"\n" .. "timezoneoffset=\"" .. timezoneoffset .. "\"\n".. "inv46=\"" .. tostring(inv46) .. "\"\n" .. "dim=\"" .. tostring(dim) .. "\"\n")
if (fcolor ~= nil) then
local hexColor=string.sub(fcolor, 1)
local red = tonumber(string.sub(hexColor, 1, 2), 16)
local green = tonumber(string.sub(hexColor, 3, 4), 16)
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
file.write("color=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
-- fill the current values
color=string.char(green, red, blue)
end
if (colorMin1 ~= nil) then
local hexColor=string.sub(colorMin1, 1)
local red = tonumber(string.sub(hexColor, 1, 2), 16)
local green = tonumber(string.sub(hexColor, 3, 4), 16)
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
file.write("color1=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
color1=string.char(green, red, blue)
end
if ( colorMin2 ~= nil) then
local hexColor=string.sub(colorMin2, 1)
local red = tonumber(string.sub(hexColor, 1, 2), 16)
local green = tonumber(string.sub(hexColor, 3, 4), 16)
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
file.write("color2=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
color2=string.char(green, red, blue)
end
if ( colorMin3 ~= nil) then
local hexColor=string.sub(colorMin3, 1)
local red = tonumber(string.sub(hexColor, 1, 2), 16)
local green = tonumber(string.sub(hexColor, 3, 4), 16)
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
file.write("color3=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
color3=string.char(green, red, blue)
end
if ( colorMin4 ~= nil) then
local hexColor=string.sub(colorMin4, 1)
local red = tonumber(string.sub(hexColor, 1, 2), 16)
local green = tonumber(string.sub(hexColor, 3, 4), 16)
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
file.write("color4=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
color4=string.char(green, red, blue)
end
if ( bcolor ~= nil) then
local hexColor=string.sub(bcolor, 1)
local red = tonumber(string.sub(hexColor, 1, 2), 16)
local green = tonumber(string.sub(hexColor, 3, 4), 16)
local blue = tonumber(string.sub(hexColor, 5, 6), 16)
file.write("colorBg=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
-- fill the current values
colorBg=string.char(green, red, blue)
end
if (getTime ~= nil) then
time = getTime(sec, timezoneoffset)
file.write("print(\"Config from " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. "\")\n")
end
if ( threequater ~= nil) then
file.write("threequater=true\n")
-- fill the current values
threequater=true
else
file.write("threequater=nil\n") -- unset threequater
-- fill the current values
threequater=nil
end
file.close()
collectgarbage()
sec=nil
file.remove(configFile)
if (file.rename(configFile .. ".new", configFile)) then
print("Rename Successfully")
else
print("Cannot rename " .. configFile .. ".new")
end
end
end