From 0e6c6840071518c942d1c4aa6aa34fc9f3c59774 Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Sun, 17 Feb 2019 14:27:27 +0100 Subject: [PATCH] =?UTF-8?q?Refactoris=C3=A9=20le=20script=20set=5Ftime.lua?= =?UTF-8?q?.=20Refactoris=C3=A9=20aussi=20l'affichage=20du=20unix=20time?= =?UTF-8?q?=20compress=C3=A9=20au=201.1.2019=20(prend=20moins=20de=20place?= =?UTF-8?q?=20en=20RAM)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WIFI_sniffer/b.lua | 24 ++++++++++++++++++++---- WIFI_sniffer/set_time.lua | 29 +++++++++++++++++------------ 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/WIFI_sniffer/b.lua b/WIFI_sniffer/b.lua index fe04541..4dc01bf 100644 --- a/WIFI_sniffer/b.lua +++ b/WIFI_sniffer/b.lua @@ -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 diff --git a/WIFI_sniffer/set_time.lua b/WIFI_sniffer/set_time.lua index 71bea27..748cc95 100644 --- a/WIFI_sniffer/set_time.lua +++ b/WIFI_sniffer/set_time.lua @@ -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())) +