Complètement refactorisé la partie lecture du fichier html de mon pico framework car elle rentrait en conflit avec d'autres scripts qui utilisaient la flash

Quasiment terminé la petite démo de la correction d'un capteur non linéaire, la démon fonctionne dans la page 3 html !
This commit is contained in:
Christian Zufferey
2019-04-22 11:40:17 +02:00
parent 155b9ae52b
commit 97c4c0fef1
8 changed files with 79 additions and 67 deletions

View File

@@ -1,7 +1,6 @@
-- petit script de serveur WEB avec Active Server Page ZYX
-- pour l'instant la partie ASP n'est que mono tâche !
print("\n web_srv2.lua zf190314.1507 \n")
print("\n web_srv2.lua zf190422.1135 \n")
ztemp=12
@@ -17,9 +16,10 @@ function send_file(zclient, zfilename)
zclient:send("Content-Type: text/html\n\n")
zzclient = zclient -- export le port sur l'environnement global !
if zfilename == "" then zfilename = "z_index.html" end
if file.open(zfilename, "r") then
file_web = file.open(zfilename, "r")
if file_web then
repeat
local line = file.read('\n')
local line = file_web:read('\n')
if line then
if string.find(line, "<%%") then
-- print("start lua...")
@@ -37,8 +37,8 @@ function send_file(zclient, zfilename)
zclient:send(line) -- envoie le code HTML
end
end
until not line
file.close()
until not line
file_web:close() file_web = nil
else
zclient:send("<html><h1>"..zfilename.." not found - 404 error</h1><a href='/'>Home</a><br></html>")
end

View File

@@ -2,42 +2,50 @@
-- ici on simule une lecture d'un device branché sur
-- l'entrée du convertisseur analogique A0
print("\n a_no_linear.lua zf19042227 \n")
print("\n a_no_linear.lua zf190422.1134 \n")
zcourbe_correction="t1.csv"
function get_correction(zx)
if file.open(zcourbe_correction, "r") then
local line = string.gsub(file.read('\n'),"\n","")
line = string.gsub(file.read('\n'),"\n","")
zx2, zy2 = zsplit(line)
function get_correction(zx0)
file_csv = file.open(zcourbe_correction, "r")
if file_csv then
local line = file_csv:readline() -- lit la première ligne header
line = file_csv:readline() zx2, zy2 = zsplit(line)
repeat
zx1 = zx2 zy1 = zy2
line = string.gsub(file.read('\n'),"\n","")
zx2, zy2 = zsplit(line)
until zx < zx2
print(zx1,zx2)
print(zy1,zy2)
file.close()
line = file_csv:readline() zx2, zy2 = zsplit(line)
until zx0 <= zx2
file_csv:close() file_csv = nil
print(zx1,zx2) print(zy1,zy2)
local zx = zx0 - zx1
local zm = zx / (zx2 - zx1)
local zy = (zy2 - zy1) * zm
zy0 = zy1 + zy
end
end
function zsplit(zline)
local zline = string.gsub(zline,"\n","")
local zx, zy = zline:match("([^,]+),([^,]+)")
print("-"..zx.."-"..zy.."-")
return tonumber(zx), tonumber(zy)
end
get_correction(100)
zx0=100
get_correction(zx0)
print("la valeur corrigée de "..zx0.." est: "..zy0)
--[[
f= "a_no_linear.lua" if file.exists(f) then dofile(f) end zget_meteo()
get_correction(83)
get_correction(91)
get_correction(100)
-- On affiche combien on a de RAM
print(node.heap())

View File

@@ -1,6 +1,6 @@
-- Scripts à charger après le boot pour démarrer son appli
print("\n boot.lua zf190311.2238 \n")
print("\n boot.lua zf19422.1102 \n")
function heartbeat()
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
@@ -21,6 +21,7 @@ f= "web_ide2.lua" if file.exists(f) then dofile(f) end
f= "web_srv2.lua" if file.exists(f) then dofile(f) end
--f= "set_time.lua" if file.exists(f) then dofile(f) end
--f= "dsleep.lua" if file.exists(f) then dofile(f) end
f= "a_no_linear.lua" if file.exists(f) then dofile(f) end
f=nil
heartbeat=nil

View File

@@ -1,7 +1,6 @@
-- petit script de serveur WEB avec Active Server Page ZYX
-- pour l'instant la partie ASP n'est que mono tâche !
print("\n web_srv2.lua zf190314.1507 \n")
print("\n web_srv2.lua zf190422.1135 \n")
ztemp=12
@@ -17,9 +16,10 @@ function send_file(zclient, zfilename)
zclient:send("Content-Type: text/html\n\n")
zzclient = zclient -- export le port sur l'environnement global !
if zfilename == "" then zfilename = "z_index.html" end
if file.open(zfilename, "r") then
file_web = file.open(zfilename, "r")
if file_web then
repeat
local line = file.read('\n')
local line = file_web:read('\n')
if line then
if string.find(line, "<%%") then
-- print("start lua...")
@@ -37,8 +37,8 @@ function send_file(zclient, zfilename)
zclient:send(line) -- envoie le code HTML
end
end
until not line
file.close()
until not line
file_web:close() file_web = nil
else
zclient:send("<html><h1>"..zfilename.." not found - 404 error</h1><a href='/'>Home</a><br></html>")
end

View File

@@ -7,12 +7,12 @@
</head>
<body>
<h1>ESP8266 home page 190217.1258</h1>
<h1>ESP8266 home page 190422.1052</h1>
<h2>Différentes pages HTML:</h2>
<h3>
<a href="z_page1.html">Page 1, affichage de la température dynamique en code Lua inline.</a><br>
<a href="z_page2.html">Page 2, tableau dynamique écrit en Lua inline.</a><br>
<a href="z_page3.html">Page 3, affichage des résultats du WIFI sniffer écrit en Lua inline.</a><br>
<a href="z_page3.html">Page 3, affichage du capteur non linéaire corrigé.</a><br>
<a href="page_qui_existe_pag.html">Page qui n'existe pas !</a><br>
</h3>
</body>

View File

@@ -7,42 +7,45 @@
</head>
<body>
<h1>ESP8266 page 3 190215.1854</h1>
<h1>ESP8266 page 3 190422.1137</h1>
<br>
Coucou c'est la page 3 !<br>
<a href="/">Retour à la home page...</a><br><br><br>
Voici le résultat du WIFI sniffer, dans un tableau dynamique écrit en Lua inline.<br><br>
Voici le résultat du capteur non linéaire corrigé avec une table
d'interpolation dans un fichier .csv sur la flash.<br><br>
Le code Lua pour créer ce tableau se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
Les données du tableau viennent du NodeMCU !<br><br>
Le code Lua pour afficher ce résultat se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
Les données viennent du NodeMCU !<br><br>
<%
zout(node.heap().."<br><br>\n")
zout("Il reste: "..node.heap().." de RAM !<br><br>\n")
%>
<table border='1'>
<tr>
<th>Index</th><th>MAC</th><th>Name</th><th>RSSI</th><th>Time0</th><th>Time1</th><th>Distance</th>
</tr>
<%
zsort_rssi()
for i=1, #zmac_adrs do
-- print(i,zmac_adrs[i])
zadrs, zname, zrssi, ztime0, ztime1 = zmac_adrs[i]:match("([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)")
zout("<tr>\n")
if tonumber(zrssi,10) < 0 then
zout("\t<td>" .. tostring(i) .. "</td>\n")
zout("\t<td>" .. zadrs .. "</td>\n")
zout("\t<td>" .. tostring(zname) .. "</td>\n")
zout("\t<td>" .. tostring(zrssi) .. "</td>\n")
zout("\t<td>" .. tostring(ztime0) .. "</td>\n")
zout("\t<td>" .. tostring(ztime1) .. "</td>\n")
zout("\t<td>" .. tostring(zround(zcalc_distance(zrssi),1)) .. "m" .. "</td>\n")
zout("</tr>\n")
end
end
zx0=83
get_correction(zx0)
zout("la valeur corrigée de "..zx0.." est: "..zy0.."<br>")
%>
<%
zx0=91
get_correction(zx0)
zout("la valeur corrigée de "..zx0.." est: "..zy0.."<br>")
%>
<%
zx0=100
get_correction(zx0)
zout("la valeur corrigée de "..zx0.." est: "..zy0.."<br>")
%>
<br>Yeah... cela fonctionne vachement bien !<br>
<%
zout("Il reste: "..node.heap().." de RAM !<br><br>\n")
%>
</table>
</body>
</html>

View File

@@ -1,7 +1,6 @@
-- petit script de serveur WEB avec Active Server Page ZYX
-- pour l'instant la partie ASP n'est que mono tâche !
print("\n web_srv2.lua zf190314.1507 \n")
print("\n web_srv2.lua zf190422.1135 \n")
ztemp=12
@@ -17,9 +16,10 @@ function send_file(zclient, zfilename)
zclient:send("Content-Type: text/html\n\n")
zzclient = zclient -- export le port sur l'environnement global !
if zfilename == "" then zfilename = "z_index.html" end
if file.open(zfilename, "r") then
file_web = file.open(zfilename, "r")
if file_web then
repeat
local line = file.read('\n')
local line = file_web:read('\n')
if line then
if string.find(line, "<%%") then
-- print("start lua...")
@@ -37,8 +37,8 @@ function send_file(zclient, zfilename)
zclient:send(line) -- envoie le code HTML
end
end
until not line
file.close()
until not line
file_web:close() file_web = nil
else
zclient:send("<html><h1>"..zfilename.." not found - 404 error</h1><a href='/'>Home</a><br></html>")
end

View File

@@ -1,7 +1,6 @@
-- petit script de serveur WEB avec Active Server Page ZYX
-- pour l'instant la partie ASP n'est que mono tâche !
print("\n web_srv2.lua zf190314.1507 \n")
print("\n web_srv2.lua zf190422.1135 \n")
ztemp=12
@@ -17,9 +16,10 @@ function send_file(zclient, zfilename)
zclient:send("Content-Type: text/html\n\n")
zzclient = zclient -- export le port sur l'environnement global !
if zfilename == "" then zfilename = "z_index.html" end
if file.open(zfilename, "r") then
file_web = file.open(zfilename, "r")
if file_web then
repeat
local line = file.read('\n')
local line = file_web:read('\n')
if line then
if string.find(line, "<%%") then
-- print("start lua...")
@@ -37,8 +37,8 @@ function send_file(zclient, zfilename)
zclient:send(line) -- envoie le code HTML
end
end
until not line
file.close()
until not line
file_web:close() file_web = nil
else
zclient:send("<html><h1>"..zfilename.." not found - 404 error</h1><a href='/'>Home</a><br></html>")
end