Setupmode modes!
This commit is contained in:
parent
1dc2530d38
commit
499cbcbbc5
84
main.lua
84
main.lua
@ -1,4 +1,5 @@
|
|||||||
-- Main Module
|
-- Main Module
|
||||||
|
ledPin=4
|
||||||
|
|
||||||
function startSetupMode()
|
function startSetupMode()
|
||||||
tmr.stop(0)
|
tmr.stop(0)
|
||||||
@ -11,9 +12,20 @@ function startSetupMode()
|
|||||||
cfg.ssid="wordclock"
|
cfg.ssid="wordclock"
|
||||||
cfg.pwd="wordclock"
|
cfg.pwd="wordclock"
|
||||||
wifi.ap.config(cfg)
|
wifi.ap.config(cfg)
|
||||||
|
|
||||||
|
-- Write the buffer to the LEDs
|
||||||
|
local color=string.char(0,128,0)
|
||||||
|
local white=string.char(0,0,0)
|
||||||
|
local ledBuf= white:rep(6) .. color .. white:rep(7) .. color:rep(3) .. white:rep(44) .. color:rep(3) .. white:rep(50)
|
||||||
|
ws2812.write(ledPin, ledBuf)
|
||||||
|
color=nil
|
||||||
|
white=nil
|
||||||
|
ledBuf=nil
|
||||||
|
|
||||||
print("Waiting in access point >wordclock< for Clients")
|
print("Waiting in access point >wordclock< for Clients")
|
||||||
print("Please visit 192.168.4.1")
|
print("Please visit 192.168.4.1")
|
||||||
startWebServer()
|
startWebServer()
|
||||||
|
collectgarbage()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -30,24 +42,30 @@ function syncTimeFromInternet()
|
|||||||
end
|
end
|
||||||
|
|
||||||
function normalOperation()
|
function normalOperation()
|
||||||
ledPin=4
|
|
||||||
-- Color is defined as GREEN, RED, BLUE
|
-- Color is defined as GREEN, RED, BLUE
|
||||||
color=string.char(0,0,250)
|
color=string.char(0,0,250)
|
||||||
|
|
||||||
connect_counter=0
|
connect_counter=0
|
||||||
-- Wait to be connect to the WiFi access point.
|
-- Wait to be connect to the WiFi access point.
|
||||||
tmr.alarm(0, 500, 1, function()
|
tmr.alarm(0, 1000, 1, function()
|
||||||
connect_counter=connect_counter+1
|
connect_counter=connect_counter+1
|
||||||
if wifi.sta.status() ~= 5 then
|
if wifi.sta.status() ~= 5 then
|
||||||
print("Connecting to AP...")
|
print(connect_counter .. "/60 Connecting to AP...")
|
||||||
if (connect_counter % 2 == 0) then
|
if (connect_counter % 2 == 0) then
|
||||||
ws2812.write(ledPin, string.char(255,0,0):rep(114))
|
ws2812.write(ledPin, string.char((connect_counter % 6)*20,(connect_counter % 5)*20,(connect_counter % 3)*20):rep(114))
|
||||||
else
|
else
|
||||||
ws2812.write(ledPin, string.char(0,0,0):rep(114))
|
ws2812.write(ledPin, string.char(0,0,0):rep(114))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
tmr.stop(0)
|
tmr.stop(0)
|
||||||
print('IP: ',wifi.sta.getip())
|
print('IP: ',wifi.sta.getip())
|
||||||
|
-- Here the WLAN is found, and something is done
|
||||||
|
print("Solving dependencies")
|
||||||
|
local dependModules = { "timecore" , "wordclock", "displayword" }
|
||||||
|
for _,mod in pairs(dependModules) do
|
||||||
|
print("Loading " .. mod)
|
||||||
|
mydofile(mod)
|
||||||
|
end
|
||||||
|
|
||||||
tmr.alarm(2, 500, 0 ,function()
|
tmr.alarm(2, 500, 0 ,function()
|
||||||
syncTimeFromInternet()
|
syncTimeFromInternet()
|
||||||
@ -58,50 +76,46 @@ function normalOperation()
|
|||||||
startWebServer()
|
startWebServer()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
-- Start the time Thread
|
||||||
|
tmr.alarm(1, 20000, 1 ,function()
|
||||||
|
sec, usec = rtctime.get()
|
||||||
|
|
||||||
|
time = getTime(sec, timezoneoffset)
|
||||||
|
print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second)
|
||||||
|
words = display_timestat(time.hour, time.minute)
|
||||||
|
ledBuf = generateLEDs(words, color)
|
||||||
|
-- Write the buffer to the LEDs
|
||||||
|
ws2812.write(ledPin, ledBuf)
|
||||||
|
|
||||||
|
-- Used for debugging
|
||||||
|
if (clockdebug ~= nil) then
|
||||||
|
for key,value in pairs(words) do
|
||||||
|
if (value > 0) then
|
||||||
|
print(key,value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- cleanup
|
||||||
|
ledBuf=nil
|
||||||
|
words=nil
|
||||||
|
time=nil
|
||||||
|
collectgarbage()
|
||||||
|
end)
|
||||||
|
|
||||||
end
|
end
|
||||||
-- when no wifi available, open an accesspoint and ask the user
|
-- when no wifi available, open an accesspoint and ask the user
|
||||||
if (connect_counter == 300) then -- 300 is 30 sec in 100ms cycle
|
if (connect_counter >= 60) then -- 300 is 30 sec in 100ms cycle
|
||||||
startSetupmode()
|
startSetupMode()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
tmr.alarm(1, 15000, 1 ,function()
|
|
||||||
sec, usec = rtctime.get()
|
|
||||||
|
|
||||||
time = getTime(sec, timezoneoffset)
|
|
||||||
print("Local time : " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second)
|
|
||||||
words = display_timestat(time.hour, time.minute)
|
|
||||||
ledBuf = generateLEDs(words, color)
|
|
||||||
-- Write the buffer to the LEDs
|
|
||||||
ws2812.write(ledPin, ledBuf)
|
|
||||||
|
|
||||||
-- Used for debugging
|
|
||||||
if (clockdebug ~= nil) then
|
|
||||||
for key,value in pairs(words) do
|
|
||||||
if (value > 0) then
|
|
||||||
print(key,value)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- cleanup
|
|
||||||
ledBuf=nil
|
|
||||||
words=nil
|
|
||||||
time=nil
|
|
||||||
collectgarbage()
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if ( file.open("config.lua") ) then
|
if ( file.open("config.lua") ) then
|
||||||
--- Normal operation
|
--- Normal operation
|
||||||
print("Solving dependencies")
|
|
||||||
dependModules = { "timecore" , "wordclock", "displayword" }
|
|
||||||
for _,mod in pairs(dependModules) do
|
|
||||||
print("Loading " .. mod)
|
|
||||||
mydofile(mod)
|
|
||||||
end
|
|
||||||
wifi.setmode(wifi.STATION)
|
wifi.setmode(wifi.STATION)
|
||||||
dofile("config.lua")
|
dofile("config.lua")
|
||||||
normalOperation()
|
normalOperation()
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
-------------
|
-------------
|
||||||
--- The webpage for the Webserver
|
--- The webpage for the Webserver
|
||||||
function sendWebPage(conn,answertype)
|
function sendWebPage(conn,answertype)
|
||||||
collectgarbage()
|
|
||||||
if (ssid == nil) then
|
if (ssid == nil) then
|
||||||
ssid="Not set"
|
ssid="Not set"
|
||||||
end
|
end
|
||||||
|
@ -10,8 +10,11 @@ function startWebServer()
|
|||||||
if (payload:find("GET /") ~= nil) then
|
if (payload:find("GET /") ~= nil) then
|
||||||
--here is code for handling http request from a web-browser
|
--here is code for handling http request from a web-browser
|
||||||
|
|
||||||
-- Load the webcontent
|
if (sendWebPage == nil) then
|
||||||
mydofile("webpage")
|
print("Loading webpage ...")
|
||||||
|
-- Load the webcontent
|
||||||
|
mydofile("webpage")
|
||||||
|
end
|
||||||
|
|
||||||
ssid, password, bssid_set, bssid = wifi.sta.getconfig()
|
ssid, password, bssid_set, bssid = wifi.sta.getconfig()
|
||||||
sendWebPage(conn,1)
|
sendWebPage(conn,1)
|
||||||
@ -20,6 +23,7 @@ function startWebServer()
|
|||||||
-- Clear the webpage generation
|
-- Clear the webpage generation
|
||||||
sendWebPage=nil
|
sendWebPage=nil
|
||||||
print("Clean webpage from RAM")
|
print("Clean webpage from RAM")
|
||||||
|
collectgarbage()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
@ -65,9 +69,7 @@ function startWebServer()
|
|||||||
if (file.rename(configFile .. ".new", configFile)) then
|
if (file.rename(configFile .. ".new", configFile)) then
|
||||||
print("Successfully")
|
print("Successfully")
|
||||||
dofile(configFile) -- load the new values
|
dofile(configFile) -- load the new values
|
||||||
print("New Config loaded")
|
|
||||||
sendWebPage(conn,2) -- success
|
sendWebPage(conn,2) -- success
|
||||||
|
|
||||||
else
|
else
|
||||||
print("Error")
|
print("Error")
|
||||||
sendWebPage(conn,3) -- error
|
sendWebPage(conn,3) -- error
|
||||||
@ -79,6 +81,7 @@ function startWebServer()
|
|||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
|
print("Hello via telnet")
|
||||||
--here is code, if the connection is not from a webbrowser, i.e. telnet or nc
|
--here is code, if the connection is not from a webbrowser, i.e. telnet or nc
|
||||||
global_c=conn
|
global_c=conn
|
||||||
function s_output(str)
|
function s_output(str)
|
||||||
|
Loading…
Reference in New Issue
Block a user