Started with a new solution where the webpage is fetched from a seperate file
This commit is contained in:
		
							
								
								
									
										20
									
								
								index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								index.html
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,20 @@
 | 
			
		||||
<html>
 | 
			
		||||
<head><title>WordClock Setup Page</title>
 | 
			
		||||
</head><body>
 | 
			
		||||
<h1>Welcome to the WordClock</h1>
 | 
			
		||||
<form action="" method="POST">
 | 
			
		||||
<table>
 | 
			
		||||
<tr><th>WIFI-SSID</b></th><td><input name="ssid" value="${SSID}"></td><td /></tr>
 | 
			
		||||
<tr><th>WIFI-Password</th><td><input name="password"></td><td /></tr>
 | 
			
		||||
<tr><th>SNTP Server</th><td><input name="sntpserver" value="${sntpserverhostname}" ></td><td>ntp server to sync the time</tr>
 | 
			
		||||
<tr><th>Offset to UTC time</th><td><input type="number" name="timezoneoffset" value="${TIMEZONEOFFSET}"></td><td>Define the offset to UTC time in hours. E.g +1</tr>
 | 
			
		||||
<tr><th>Color</th><td><input type="color" name="fcolor" value="${HEXCOLOR}"></td><td /></tr>
 | 
			
		||||
<tr><th>1. Minute Color</th><td><input type=\"color\" name=\"colorMin1\" value=\"" .. hexColor1 .. "\"></td><td /></tr>"
 | 
			
		||||
<tr><th>2. Minute Color</th><td><input type=\"color\" name=\"colorMin2\" value=\"" .. hexColor2 .. "\"></td><td /></tr>"
 | 
			
		||||
<tr><th>3. Minute Color</th><td><input type=\"color\" name=\"colorMin3\" value=\"" .. hexColor3 .. "\"></td><td /></tr>"
 | 
			
		||||
<tr><th>4. Minute Color</th><td><input type=\"color\" name=\"colorMin4\" value=\"" .. hexColor4 .. "\"></td><td /></tr>"
 | 
			
		||||
<tr><th>Three quater</th><td><input type="checkbox" name="threequater" ${THREEQUARTERCHECKED}></td><td>Dreiviertel Joa/nei</td></tr>
 | 
			
		||||
<tr><th>ColorMode</th><td><input type="checkbox" name="colorMode" ${COLORMODECHECKED}></td><td>If checked, words are dark, rest is colored</td></tr>
 | 
			
		||||
<tr><td colspan=\"3\"><div align=\"center\"><input type=\"submit\" value=\"Save Configuration\" onclick=\"this.value='Submitting ..';this.disabled='disabled'; this.form.submit();\"></div></td></tr>"
 | 
			
		||||
<tr><td colspan=\"3\"><div align=\"center\"><input type=\"submit\" name=\"action\" value=\"Reboot\"></div></td></tr>"
 | 
			
		||||
</table></form>"
 | 
			
		||||
							
								
								
									
										3
									
								
								main.lua
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								main.lua
									
									
									
									
									
								
							@@ -58,7 +58,8 @@ function displayTime()
 | 
			
		||||
        color=color4
 | 
			
		||||
     end
 | 
			
		||||
     
 | 
			
		||||
     ledBuf = generateLEDs(words, color)
 | 
			
		||||
     ledBuf = generateLEDs(words, color, colorMode)
 | 
			
		||||
     
 | 
			
		||||
     -- Write the buffer to the LEDs
 | 
			
		||||
     ws2812.write(ledBuf)
 | 
			
		||||
    
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										22
									
								
								webpage.lua
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								webpage.lua
									
									
									
									
									
								
							@@ -34,14 +34,23 @@ function sendWebPage(conn,answertype)
 | 
			
		||||
  local hexColor4 = "#" .. string.format("%02x",string.byte(color4,1)) .. string.format("%02x",string.byte(color4,2)) .. string.format("%02x",string.byte(color4,3))
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
  local buf="HTTP/1.1 200 OK\nServer: NodeMCU\nContent-Type: text/html\n\n"
 | 
			
		||||
  if (node.heap() < 8000) then
 | 
			
		||||
    buf = buf .. "<h1>Busy, please come later again</h1>"
 | 
			
		||||
    endOfPage=true
 | 
			
		||||
  else
 | 
			
		||||
 | 
			
		||||
  -- hack for the second part of the page
 | 
			
		||||
  buf=nil
 | 
			
		||||
  if (answertype==10) then
 | 
			
		||||
      buf = "<tr><th>Color 1. Minute</th><td><input type=\"color\" name=\"colorMin1\" value=\"" .. hexColor1 .. "\"></td><td /></tr>"
 | 
			
		||||
      buf = buf .."<tr><th>Color 2. Minute</th><td><input type=\"color\" name=\"colorMin2\" value=\"" .. hexColor2 .. "\"></td><td /></tr>"
 | 
			
		||||
      buf = buf .."<tr><th>Color 3. Minute</th><td><input type=\"color\" name=\"colorMin3\" value=\"" .. hexColor3 .. "\"></td><td /></tr>"
 | 
			
		||||
      buf = buf .."<tr><th>Color 4. Minute</th><td><input type=\"color\" name=\"colorMin4\" value=\"" .. hexColor4 .. "\"></td><td /></tr>"
 | 
			
		||||
      buf = "<tr><th>1. Minute Color</th><td><input type=\"color\" name=\"colorMin1\" value=\"" .. hexColor1 .. "\"></td><td /></tr>"
 | 
			
		||||
      buf = buf .."<tr><th>2. Minute Color</th><td><input type=\"color\" name=\"colorMin2\" value=\"" .. hexColor2 .. "\"></td><td /></tr>"
 | 
			
		||||
      buf = buf .."<tr><th>3. Minute Color</th><td><input type=\"color\" name=\"colorMin3\" value=\"" .. hexColor3 .. "\"></td><td /></tr>"
 | 
			
		||||
      buf = buf .."<tr><th>4. Minute Color</th><td><input type=\"color\" name=\"colorMin4\" value=\"" .. hexColor4 .. "\"></td><td /></tr>"
 | 
			
		||||
      buf = buf .."<tr><th>Three quater</th><td><input type=\"checkbox\" name=\"threequater\" ".. (threequater and "checked" or "") .. "></td><td>Dreiviertel Joa/nei</td></tr>"
 | 
			
		||||
      --buf = buf .."<tr><th>ColorMode</th><td><input type=\"checkbox\" name=\"threequater\" ".. (colorMode and "checked" or "") .. "></td><td>If checked, words are dark, rest is colored</td></tr>"
 | 
			
		||||
      buf = buf .. "<tr><td colspan=\"3\"><div align=\"center\"><input type=\"submit\" value=\"Save Configuration\" onclick=\"this.value='Submitting ..';this.disabled='disabled'; this.form.submit();\"></div></td></tr>"
 | 
			
		||||
      buf = buf .. "<tr><td colspan=\"3\"><div align=\"center\"><input type=\"submit\" name=\"action\" value=\"Reboot\"></div></td></tr>"
 | 
			
		||||
      buf = buf .."</table></form>"
 | 
			
		||||
@@ -52,12 +61,7 @@ function sendWebPage(conn,answertype)
 | 
			
		||||
      endOfPage=true
 | 
			
		||||
      return
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  
 | 
			
		||||
  local buf="HTTP/1.1 200 OK\nServer: NodeMCU\nContent-Type: text/html\n\n"
 | 
			
		||||
  if (node.heap() < 8000) then
 | 
			
		||||
  buf = buf .. "<h1>Busy, please come later again</h1>"
 | 
			
		||||
  else
 | 
			
		||||
  buf = buf .. "<html>"
 | 
			
		||||
  buf = buf .. "<head><title>WordClock Setup Page</title>"
 | 
			
		||||
  buf = buf .. "</head><body>\n"
 | 
			
		||||
 
 | 
			
		||||
@@ -113,6 +113,11 @@ function startWebServer()
 | 
			
		||||
        local blue = tonumber(string.sub(hexColor, 5, 6), 16)
 | 
			
		||||
        file.write("color4=string.char(" .. green .. "," .. red .. "," .. blue .. ")\n")
 | 
			
		||||
      end
 | 
			
		||||
      if ( _POST.colorMode ~= nil) then
 | 
			
		||||
        file.write("colorMode=true\n")
 | 
			
		||||
      else
 | 
			
		||||
        file.write("colorMode=nil\n") -- unset colorMode
 | 
			
		||||
      end
 | 
			
		||||
      time = getTime(sec, timezoneoffset)
 | 
			
		||||
      file.write("color=string.char(" .. string.byte(color,1) .. "," .. string.byte(color, 2) .. "," .. string.byte(color, 3) .. ")\n")
 | 
			
		||||
      file.write("print(\"Config from " .. time.year .. "-" .. time.month .. "-" .. time.day .. " " .. time.hour .. ":" .. time.minute .. ":" .. time.second .. "\")\n")
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user