Refactorisé le script set_time.lua. Refactorisé aussi l'affichage du unix time compressé au 1.1.2019 (prend moins de place en RAM)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
-- Scripts pour tester le sniffer de smartphone qui essaient de se connecter sur des AP WIFI
|
||||
-- source: https://nodemcu.readthedocs.io/en/dev/modules/wifi/#wifieventmonregister
|
||||
|
||||
print("\n b.lua zf190217.1253 \n")
|
||||
print("\n b.lua zf190217.1423 \n")
|
||||
|
||||
--f= "set_time.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
@@ -28,12 +28,16 @@ zmac_adrs[#zmac_adrs+1]="da:a1:19:89:2c:80, ,-59,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="da:a1:19:01:85:98, ,-47,0,0"
|
||||
]]
|
||||
|
||||
|
||||
function zshow()
|
||||
for i=1, #zmac_adrs do
|
||||
-- print(i,zmac_adrs[i])
|
||||
zadrs, zname, zrssi, ztime0, ztime1 = zmac_adrs[i]:match("([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)")
|
||||
print(i.."-"..zadrs..", "..zname..", "..zrssi..", "..ztime0..", "..ztime1.."-"..zround(zcalc_distance(zrssi),1).."m")
|
||||
if tonumber(zrssi) < 0 then
|
||||
ztx = i.."-"..zadrs..", "..zname..", "..zrssi..", "..zround(zcalc_distance(zrssi),1).."m, "
|
||||
ztx = ztx..ztime_format(ztime_uncompress(ztime0))..", "..ztime_format(ztime_uncompress(ztime1))
|
||||
print(ztx)
|
||||
ztx = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -92,6 +96,8 @@ function zround(num, dec)
|
||||
return math.floor(num * mult + 0.5) / mult
|
||||
end
|
||||
|
||||
|
||||
|
||||
--zadrs, zname, zrssi, ztime0, ztime1
|
||||
|
||||
function zsniff(T)
|
||||
@@ -113,6 +119,16 @@ function zsniff(T)
|
||||
end
|
||||
-- zmac_adrs[T.MAC]["ztime"]=string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"])
|
||||
|
||||
if tonumber(ztime0) == 0 then
|
||||
ztime0 = ztime_compress(rtctime.get())
|
||||
else
|
||||
if ztime_uncompress(ztime0) < ztime2019 then
|
||||
ztime0 = ztime_compress(rtctime.get())
|
||||
end
|
||||
end
|
||||
ztime1 = ztime_compress(rtctime.get())
|
||||
|
||||
|
||||
zrssi=T.RSSI
|
||||
--[[
|
||||
if zrssi == 0 then
|
||||
@@ -122,7 +138,7 @@ function zsniff(T)
|
||||
end
|
||||
]]
|
||||
if zname ~= " " then
|
||||
print("Bonjour "..zname.." !")
|
||||
print("Bonjour "..zname.." ! "..zrssi)
|
||||
end
|
||||
zmac_adrs[z_adrs_mac_index]=zmerge()
|
||||
end
|
||||
|
||||
@@ -1,24 +1,29 @@
|
||||
-- Scripts pour régler l'horloge quand on est connecté en WIFI
|
||||
-- Permet aussi de 'compresser' le unix time afin de prendre moins de place dans les strings
|
||||
|
||||
print("\n set_time.lua zf190119.1728 \n")
|
||||
|
||||
--f= "wifi_ap_stop.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "wifi_cli_conf.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "wifi_cli_start.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "telnet_srv.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "web_ide2.lua" if file.exists(f) then dofile(f) end
|
||||
--f= "dsleep.lua" if file.exists(f) then dofile(f) end
|
||||
print("\n set_time.lua zf190217.1426 \n")
|
||||
|
||||
--source: https://www.freeformatter.com/epoch-timestamp-to-date-converter.html
|
||||
|
||||
ztime2019 = 1546300800 -- Unix time pour le 1.1.2019
|
||||
|
||||
function set_time()
|
||||
sntp.sync(nil, nil, nil, 1)
|
||||
end
|
||||
|
||||
function ztime()
|
||||
tm = rtctime.epoch2cal(rtctime.get()+3600)
|
||||
print(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]))
|
||||
function ztime_compress(ztime_long)
|
||||
return ztime_long - ztime2019
|
||||
end
|
||||
|
||||
function ztime_uncompress(ztime_short)
|
||||
return ztime_short + ztime2019
|
||||
end
|
||||
|
||||
function ztime_format(ztime)
|
||||
tm = rtctime.epoch2cal(ztime + 3600)
|
||||
return(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]))
|
||||
end
|
||||
|
||||
set_time()
|
||||
ztime()
|
||||
print(ztime_format(rtctime.get()))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user