Trouvé le problème, c'était à nouveau une ligne dans le fichier .html qui était plus longue que 128 bytes :-( Profité pour nettoyer le code du serveur WEB ASP ZYX ;-)
This commit is contained in:
@@ -1,16 +1,7 @@
|
||||
-- petit script de serveur WEB avec Active Server Page ZYX
|
||||
-- permet d'exécuter du code LUA inline dans l'HTML !
|
||||
|
||||
print("\n web_srv2.lua zf191222.2335 \n")
|
||||
|
||||
-- dû refaire la commande file.readline car elle bug quand ligne longue
|
||||
function zread_line()
|
||||
local zline = ""
|
||||
while true do
|
||||
local t = file_web:read(1) if t == nil then return end
|
||||
zline = zline..t
|
||||
if t == "\n" then return zline end
|
||||
end
|
||||
end
|
||||
print("\n web_srv2.lua zf200112.1530 \n")
|
||||
|
||||
-- envoie sur le port ouvert mais depuis l'environnement global !
|
||||
function zout(zstring)
|
||||
@@ -28,24 +19,16 @@ function send_file(zclient, zfilename)
|
||||
if file_web then
|
||||
repeat
|
||||
local line = file_web:readline()
|
||||
-- local line = file_web:read('\n')
|
||||
-- local line = zread_line()
|
||||
-- print("hello toto",string.len(line))
|
||||
if line then
|
||||
if string.find(line, "<%%") then
|
||||
-- print("start lua...")
|
||||
flag_lua_code = true -- bascule sur le code lua inline
|
||||
lua_code = ""
|
||||
elseif string.find(line, "%%>") then
|
||||
-- print("stop lua...")
|
||||
flag_lua_code = false -- revient sur le code HTML
|
||||
-- print("Et voici le code lua inline:\n"..lua_code)
|
||||
loadstring(lua_code)() --on exécute ici le code lua inline !
|
||||
elseif flag_lua_code then
|
||||
-- print(line)
|
||||
lua_code = lua_code..line -- récupère le code lua inline
|
||||
else
|
||||
-- print(line)
|
||||
zclient:send(line) -- envoie le code HTML
|
||||
end
|
||||
end
|
||||
@@ -56,16 +39,10 @@ function send_file(zclient, zfilename)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
srv = net.createServer()
|
||||
srv:listen(80, function(conn)
|
||||
conn:on("receive", function(client, request)
|
||||
_, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
|
||||
|
||||
-- print("zrequest: \n---\n"..request.."---")
|
||||
|
||||
-- print("method: ", method) print("path: ", path) print("vars: ", vars)
|
||||
|
||||
if not string.find(request, "/favicon.ico") then
|
||||
print("coucou")
|
||||
if (method == nil) then
|
||||
@@ -80,7 +57,6 @@ srv:listen(80, function(conn)
|
||||
end
|
||||
end
|
||||
file_html=string.gsub(path, "/", "")
|
||||
-- print("file_html: ",file_html)
|
||||
send_file(client, file_html)
|
||||
end
|
||||
end)
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<!-- ATTENTION, la longueur des lignes DOIT être <128 ! -->
|
||||
|
||||
<html lang="fr" dir="ltr">
|
||||
<head>
|
||||
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>SonOff home page</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>SonOff home page 2001011.1351</h1>
|
||||
<h1>SonOff home page 2001012.1526</h1>
|
||||
<a href="/">Home...</a><br>
|
||||
<h2>Menu:</h2>
|
||||
<h3>
|
||||
|
||||
|
||||
SonOff API LED
|
||||
<a href="api_sonoff.html?LED=on"> On</a>
|
||||
<a href="api_sonoff.html?LED=off"> Off</a><br>
|
||||
@@ -39,7 +42,7 @@
|
||||
print("On demande le setup wifi depuis le browser !")
|
||||
wifi_setup_ok=(math.floor(100*node.random()))
|
||||
zout("<br><br>Etes-vous vraiment certain ?<br>Si oui, faites: ")
|
||||
zout('<a href="/?SetupWIFI='..wifi_setup_ok..'"> Ok</a><br><br>')
|
||||
zout('<a href="/?SetupWIFI='..wifi_setup_ok..'"> Ok</a><br><br>')
|
||||
end
|
||||
%>
|
||||
|
||||
@@ -74,7 +77,7 @@
|
||||
zout("<br>")
|
||||
%>
|
||||
|
||||
<%
|
||||
<%
|
||||
if zRELAY ~= nil then
|
||||
zout("Etat du RELAY:<nsp>")
|
||||
if gpio.read(zRELAY) == 0 then zout("OFF") else zout("ON") end
|
||||
@@ -85,7 +88,9 @@
|
||||
<%
|
||||
a,b,c = wifi.sta.getip()
|
||||
if a ~= nil then
|
||||
zout("<br><br>IP: "..a.." MASK: "..b.." GATEWAY: "..c.."<br>")
|
||||
zout("<br>IP: "..a.."<br>")
|
||||
zout("MASK: "..b.."<br>")
|
||||
zout("GATEWAY: "..c.."<br>")
|
||||
end
|
||||
collectgarbage() zout("RAM: "..node.heap())
|
||||
%>
|
||||
|
||||
Reference in New Issue
Block a user