Gros problème pour mon script dir2.lua, il bloque trop longtemps le NodeMCU et est inutilisable en en remote telnet. Je dois utiliser un callback

This commit is contained in:
Christian Zufferey
2019-11-24 14:37:08 +01:00
parent cd354cba35
commit 3d0389d8c4
7 changed files with 252 additions and 38 deletions

View File

@@ -12,7 +12,7 @@
# définitions à faire AVANT !
cd /Users/zuzu/Desktop/NodeMCU/NodeMCU_Lua/WIFI_sniffer/cret_project
export luatool_tty="/dev/cu.wchusbserial1410"
export zIP="192.168.0.137"
export zIP="192.168.0.122"
export zport="23"
cd '/Users/zuzu/Google Drive/FamilleZ Share/FamilleZ/Papa/LUA/NodeMCU ESP8266/NodeMCU_Lua/WIFI_sniffer/cret_project'
@@ -31,6 +31,15 @@ for k,v in pairs(_G) do print(k,v) end
# commandes lua pour ce projet
telnet -rN $zIP $zport
wifi.eventmon.unregister(wifi.eventmon.AP_PROBEREQRECVED)
dofile("dir2.lua")
filec('dir2.lua')
dirc()
~.
verbose=true
verbose=false
zsort_rssi() zshow()

View File

@@ -0,0 +1,26 @@
-- Scripts pour tester le multi-tâche
function lenteur()
print("in...")
tmr.delay(1*1000*1000)
print("out...")
i=i+1
zrepeat()
end
function zrepeat()
if i<5 then
node.task.post(lenteur)
end
print("out2...")
end
t1=tmr.now()
i=0
zrepeat()
t2=tmr.now()
print("durée: "..t2-t1)

View File

@@ -1,52 +1,63 @@
-- fonction dir() pour calculer le checksum de tous les fichiers sur le NodeMCU !
-- fonction dirfile(fichier) pour calculer le checksum d'un seul fichiers sur le NodeMCU !
print("\n dir2.lua zf191123.1410 \n")
print("\n dir2.lua zf191124.1343 \n")
function calc_chksum_file(name_file)
size_file = 1 chksum_file = 0
-- local f = io.open(name_file, "r")
local f = file.open(name_file, "r")
while true do
local t = f:read(1) if t == nil then break end
chksum_file = chksum_file + size_file * string.byte(t)
size_file = size_file + 1
if size_file%100 == 0 then uart.write(0,".") end
function dir2()
function calc_chksum_file(name_file)
print(name_file)
size_file = 1 chksum_file = 0
local f = file.open(name_file, "r")
while true do
local t = f:read(1) if t == nil then break end
chksum_file = chksum_file + size_file * string.byte(t)
size_file = size_file + 1
if size_file%100 == 0 then uart.write(0,".") end
end
f:close() print("")
end
f:close()
print(name_file)
end
function dirfile(k)
calc_chksum_file(k)
print(k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file)
size_file=nil chksum_file=nil k=nil
end
function dir()
local zdir={}
-- local pfile = io.popen("ls -1r ")
-- for k in pfile:lines() do
local pfile = file.list()
for k,v in pairs(pfile) do
function filec(k)
calc_chksum_file(k)
if (size_file ~= 1) and (chksum_file ~= 1) then
print(k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file)
size_file=nil chksum_file=nil k=nil
end
function dir()
local zdir={}
local pfile = file.list()
for k,v in pairs(pfile) do
zdir[#zdir+1] = k..string.rep(" ",24-string.len(k)).." : "..v
end
table.sort(zdir) for i=1, #zdir do print(zdir[i]) end
size_file=nil chksum_file=nil k=nil
end
function dirc()
local zdir={}
local pfile = file.list()
for k,v in pairs(pfile) do
calc_chksum_file(k)
zdir[#zdir+1]=k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file
end
table.sort(zdir) for i=1, #zdir do print(zdir[i]) end
size_file=nil chksum_file=nil k=nil
end
-- pfile:close()
table.sort(zdir)
for i=1, #zdir do
print(zdir[i])
end
size_file=nil chksum_file=nil k=nil
end
--dir()
dir()
print("\nusage:")
print(" dir()")
print(" dirc()")
print(" filec('dir2.lua')")
end
dir2()
--[[
dir()
dirfile("dir2.lua")
dirc()
filec("dir2.lua")
for k,v in pairs(_G) do print(k,v) end

View File

@@ -0,0 +1,65 @@
-- fonction dir() pour calculer le checksum de tous les fichiers sur le NodeMCU !
-- fonction dirfile(fichier) pour calculer le checksum d'un seul fichiers sur le NodeMCU !
print("\n dir2.lua zf191124.1343 \n")
function dir2()
function calc_chksum_file(name_file)
print(name_file)
size_file = 1 chksum_file = 0
local f = file.open(name_file, "r")
while true do
local t = f:read(1) if t == nil then break end
chksum_file = chksum_file + size_file * string.byte(t)
size_file = size_file + 1
if size_file%100 == 0 then uart.write(0,".") end
end
f:close() print("")
end
function filec(k)
calc_chksum_file(k)
print(k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file)
size_file=nil chksum_file=nil k=nil
end
function dir()
local zdir={}
local pfile = file.list()
for k,v in pairs(pfile) do
zdir[#zdir+1] = k..string.rep(" ",24-string.len(k)).." : "..v
end
table.sort(zdir) for i=1, #zdir do print(zdir[i]) end
size_file=nil chksum_file=nil k=nil
end
function dirc()
local zdir={}
local pfile = file.list()
for k,v in pairs(pfile) do
calc_chksum_file(k)
zdir[#zdir+1]=k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file
end
table.sort(zdir) for i=1, #zdir do print(zdir[i]) end
size_file=nil chksum_file=nil k=nil
end
dir()
print("\nusage:")
print(" dir()")
print(" dirc()")
print(" filec('dir2.lua')")
end
dir2()
--[[
dir()
dirc()
filec("dir2.lua")
for k,v in pairs(_G) do print(k,v) end
status, err = pcall(function () print(zhash("il était une fois trois petits cochons roses...")) end) if status==false then print("Error: ",err) end
]]

View File

@@ -3,11 +3,16 @@
-- du dossier en cours, donc PAS sur le NodeMCU !
-- source: https://stackoverflow.com/questions/5303174/how-to-get-list-of-directories-in-lua (30%)
-- usage:
-- usage dans la console:
-- ./zz_host_dir2.lua
-- ./zz_host_dir2.lua > thost
print("\n zz_host_dir2.lua zf191124.1054 \n")
-- usage dans Atom editor
-- il faut installer ceci: https://atom.io/packages/compare-files
-- puis sélectionner les deux fichiers dans l'explorateur à gauche puis CTRL+CMD+C
print("\n zz_host_dir2.lua zf191124.1109 \n")
function calc_chksum_file(name_file)
size_file = 1 chksum_file = 0

View File

@@ -0,0 +1,37 @@
zz_host_dir2.lua zf191124.1054
README.md : 2841, 347247457
_secrets_project.lua_ : 574, 14047690
_secrets_wifit.lua_ : 574, 14047690
_zremote_cmd.txt : 3205, 425932059
b.lua : 4289, 696634446
boot.lua : 451, 8092291
boot2.lua : 1581, 89772835
c.lua : 1023, 45354296
cat.lua : 522, 9721978
dir.lua : 426, 6099749
flash_led_xfois.lua : 1143, 44689874
head.lua : 567, 11507510
initz.lua : 2159, 175035891
luatool.py : 14426, 7814354905
secrets_project.lua : 539, 12833508
secrets_wifi.lua : 640, 15516580
set_time.lua : 879, 31173858
telnet_srv2.lua : 2760, 289194718
thost : 40, 43647
upload_s.sh : 1855, 144236402
upload_t.sh : 1618, 109879609
web_srv2.lua : 2960, 297644504
wifi_info.lua : 1604, 98582260
wifi_init.lua : 501, 10271357
z_index.html : 1015, 44275501
z_page1.html : 443, 7731060
z_page2.html : 1867, 123937742
z_page3.html : 1415, 67091731
z_page4.html : 1660, 90364904
zz_host_dir2.lua : 1821, 131648152
Rappel, sur Atom, sélectionner les deux fichiers à gauche puis CTRL+CMD+C

View File

@@ -0,0 +1,61 @@
#!/usr/local/bin/lua5.1
-- script lua à faire tourner sur le host pour calculer le checksum de tous les fichiers
-- du dossier en cours, donc PAS sur le NodeMCU !
-- source: https://stackoverflow.com/questions/5303174/how-to-get-list-of-directories-in-lua (30%)
-- usage:
-- ./zz_host_dir2.lua
-- ./zz_host_dir2.lua > thost
print("\n zz_host_dir2.lua zf191124.1054 \n")
function calc_chksum_file(name_file)
size_file = 1 chksum_file = 0
local f = io.open(name_file, "r")
-- local f = file.open(name_file, "r")
while true do
local t = f:read(1) if t == nil then break end
chksum_file = chksum_file + size_file * string.byte(t)
size_file = size_file + 1
-- if size_file%100 == 0 then uart.write(0,".") end
end
f:close()
-- print(name_file)
end
function dirfile(k)
calc_chksum_file(k)
print(k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file)
size_file=nil chksum_file=nil k=nil
end
function dir()
local zdir={}
local pfile = io.popen("ls -1r ")
for k in pfile:lines() do
-- local pfile = file.list()
-- for k,v in pairs(pfile) do
calc_chksum_file(k)
if (size_file ~= 1) and (chksum_file ~= 1) then
zdir[#zdir+1]=k..string.rep(" ",24-string.len(k)).." : "..size_file..", "..chksum_file
end
end
pfile:close()
table.sort(zdir)
for i=1, #zdir do
print(zdir[i])
end
size_file=nil chksum_file=nil k=nil
end
dir()
print("\n\nRappel, sur Atom, sélectionner les deux fichiers à gauche puis CTRL+CMD+C\n")
--[[
dir()
dirfile("dir2.lua")
for k,v in pairs(_G) do print(k,v) end
status, err = pcall(function () print(zhash("il était une fois trois petits cochons roses...")) end) if status==false then print("Error: ",err) end
]]