From 97c4c0fef12000a51e601670d43c390d3bed4003 Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Mon, 22 Apr 2019 11:40:17 +0200 Subject: [PATCH] =?UTF-8?q?Compl=C3=A8tement=20refactoris=C3=A9=20la=20par?= =?UTF-8?q?tie=20lecture=20du=20fichier=20html=20de=20mon=20pico=20framewo?= =?UTF-8?q?rk=20car=20elle=20rentrait=20en=20conflit=20avec=20d'autres=20s?= =?UTF-8?q?cripts=20qui=20utilisaient=20la=20flash=20Quasiment=20termin?= =?UTF-8?q?=C3=A9=20la=20petite=20d=C3=A9mo=20de=20la=20correction=20d'un?= =?UTF-8?q?=20capteur=20non=20lin=C3=A9aire,=20la=20d=C3=A9mon=20fonctionn?= =?UTF-8?q?e=20dans=20la=20page=203=20html=20!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Meteo/web_srv2.lua | 12 +++---- No_linear/a_no_linear.lua | 36 ++++++++++++--------- No_linear/boot.lua | 3 +- No_linear/web_srv2.lua | 12 +++---- No_linear/z_index.html | 4 +-- No_linear/z_page3.html | 55 +++++++++++++++++---------------- WIFI_sniffer/web_srv2.lua | 12 +++---- ZYX-html-framework/web_srv2.lua | 12 +++---- 8 files changed, 79 insertions(+), 67 deletions(-) diff --git a/Meteo/web_srv2.lua b/Meteo/web_srv2.lua index e69ac66..a7b5953 100644 --- a/Meteo/web_srv2.lua +++ b/Meteo/web_srv2.lua @@ -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("

"..zfilename.." not found - 404 error

Home
") end diff --git a/No_linear/a_no_linear.lua b/No_linear/a_no_linear.lua index 6837f2c..421389d 100644 --- a/No_linear/a_no_linear.lua +++ b/No_linear/a_no_linear.lua @@ -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()) diff --git a/No_linear/boot.lua b/No_linear/boot.lua index 5ea3f27..917e172 100644 --- a/No_linear/boot.lua +++ b/No_linear/boot.lua @@ -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 diff --git a/No_linear/web_srv2.lua b/No_linear/web_srv2.lua index e69ac66..a7b5953 100644 --- a/No_linear/web_srv2.lua +++ b/No_linear/web_srv2.lua @@ -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("

"..zfilename.." not found - 404 error

Home
") end diff --git a/No_linear/z_index.html b/No_linear/z_index.html index 1d70f76..dd689c8 100644 --- a/No_linear/z_index.html +++ b/No_linear/z_index.html @@ -7,12 +7,12 @@ -

ESP8266 home page 190217.1258

+

ESP8266 home page 190422.1052

Différentes pages HTML:

Page 1, affichage de la température dynamique en code Lua inline.
Page 2, tableau dynamique écrit en Lua inline.
- Page 3, affichage des résultats du WIFI sniffer écrit en Lua inline.
+ Page 3, affichage du capteur non linéaire corrigé.
Page qui n'existe pas !

diff --git a/No_linear/z_page3.html b/No_linear/z_page3.html index ae96cf4..7e6bb77 100644 --- a/No_linear/z_page3.html +++ b/No_linear/z_page3.html @@ -7,42 +7,45 @@ -

ESP8266 page 3 190215.1854

+

ESP8266 page 3 190422.1137


Coucou c'est la page 3 !
Retour à la home page...


- Voici le résultat du WIFI sniffer, dans un tableau dynamique écrit en Lua inline.

+ Voici le résultat du capteur non linéaire corrigé avec une table + d'interpolation dans un fichier .csv sur la flash.

- Le code Lua pour créer ce tableau se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.
- Les données du tableau viennent du NodeMCU !

+ Le code Lua pour afficher ce résultat se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.
+ Les données viennent du NodeMCU !

<% - zout(node.heap().."

\n") + zout("Il reste: "..node.heap().." de RAM !

\n") %> - - - - - + <% - zsort_rssi() - for i=1, #zmac_adrs do - -- print(i,zmac_adrs[i]) - zadrs, zname, zrssi, ztime0, ztime1 = zmac_adrs[i]:match("([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)") - zout("\n") - if tonumber(zrssi,10) < 0 then - zout("\t\n") - zout("\t\n") - zout("\t\n") - zout("\t\n") - zout("\t\n") - zout("\t\n") - zout("\t\n") - zout("\n") - end - end + zx0=83 + get_correction(zx0) + zout("la valeur corrigée de "..zx0.." est: "..zy0.."
") %> + + <% + zx0=91 + get_correction(zx0) + zout("la valeur corrigée de "..zx0.." est: "..zy0.."
") + %> + + <% + zx0=100 + get_correction(zx0) + zout("la valeur corrigée de "..zx0.." est: "..zy0.."
") + %> + +
Yeah... cela fonctionne vachement bien !
+ + <% + zout("Il reste: "..node.heap().." de RAM !

\n") + %> +
IndexMACNameRSSITime0Time1Distance
" .. tostring(i) .. "" .. zadrs .. "" .. tostring(zname) .. "" .. tostring(zrssi) .. "" .. tostring(ztime0) .. "" .. tostring(ztime1) .. "" .. tostring(zround(zcalc_distance(zrssi),1)) .. "m" .. "
diff --git a/WIFI_sniffer/web_srv2.lua b/WIFI_sniffer/web_srv2.lua index e69ac66..a7b5953 100644 --- a/WIFI_sniffer/web_srv2.lua +++ b/WIFI_sniffer/web_srv2.lua @@ -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("

"..zfilename.." not found - 404 error

Home
") end diff --git a/ZYX-html-framework/web_srv2.lua b/ZYX-html-framework/web_srv2.lua index e69ac66..a7b5953 100644 --- a/ZYX-html-framework/web_srv2.lua +++ b/ZYX-html-framework/web_srv2.lua @@ -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("

"..zfilename.." not found - 404 error

Home
") end