diff --git a/DeepSleep/ESP-M3/a.lua b/DeepSleep/Pet_tracker/a.lua similarity index 100% rename from DeepSleep/ESP-M3/a.lua rename to DeepSleep/Pet_tracker/a.lua diff --git a/DeepSleep/ESP-M3/a_test_power_wifi.lua b/DeepSleep/Pet_tracker/a_test_power_wifi.lua similarity index 100% rename from DeepSleep/ESP-M3/a_test_power_wifi.lua rename to DeepSleep/Pet_tracker/a_test_power_wifi.lua diff --git a/DeepSleep/ESP-M3/boot.lua b/DeepSleep/Pet_tracker/boot.lua similarity index 100% rename from DeepSleep/ESP-M3/boot.lua rename to DeepSleep/Pet_tracker/boot.lua diff --git a/DeepSleep/ESP-M3/dsleep.lua b/DeepSleep/Pet_tracker/dsleep.lua similarity index 100% rename from DeepSleep/ESP-M3/dsleep.lua rename to DeepSleep/Pet_tracker/dsleep.lua diff --git a/DeepSleep/ESP-M3/flash_led_xfois.lua b/DeepSleep/Pet_tracker/flash_led_xfois.lua similarity index 100% rename from DeepSleep/ESP-M3/flash_led_xfois.lua rename to DeepSleep/Pet_tracker/flash_led_xfois.lua diff --git a/DeepSleep/ESP-M3/goodies/a_test_fill.lua b/DeepSleep/Pet_tracker/goodies/a_test_fill.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/a_test_fill.lua rename to DeepSleep/Pet_tracker/goodies/a_test_fill.lua diff --git a/DeepSleep/ESP-M3/goodies/a_train1.lua b/DeepSleep/Pet_tracker/goodies/a_train1.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/a_train1.lua rename to DeepSleep/Pet_tracker/goodies/a_train1.lua diff --git a/DeepSleep/ESP-M3/goodies/blink_led1.lua b/DeepSleep/Pet_tracker/goodies/blink_led1.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/blink_led1.lua rename to DeepSleep/Pet_tracker/goodies/blink_led1.lua diff --git a/DeepSleep/ESP-M3/goodies/blink_led2.lua b/DeepSleep/Pet_tracker/goodies/blink_led2.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/blink_led2.lua rename to DeepSleep/Pet_tracker/goodies/blink_led2.lua diff --git a/DeepSleep/ESP-M3/goodies/cat.lua b/DeepSleep/Pet_tracker/goodies/cat.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/cat.lua rename to DeepSleep/Pet_tracker/goodies/cat.lua diff --git a/DeepSleep/ESP-M3/goodies/credentials.lua b/DeepSleep/Pet_tracker/goodies/credentials.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/credentials.lua rename to DeepSleep/Pet_tracker/goodies/credentials.lua diff --git a/DeepSleep/ESP-M3/goodies/dir.lua b/DeepSleep/Pet_tracker/goodies/dir.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/dir.lua rename to DeepSleep/Pet_tracker/goodies/dir.lua diff --git a/DeepSleep/ESP-M3/goodies/flash_led_xfois.lua b/DeepSleep/Pet_tracker/goodies/flash_led_xfois.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/flash_led_xfois.lua rename to DeepSleep/Pet_tracker/goodies/flash_led_xfois.lua diff --git a/DeepSleep/ESP-M3/goodies/initz - copie.lua b/DeepSleep/Pet_tracker/goodies/initz - copie.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/initz - copie.lua rename to DeepSleep/Pet_tracker/goodies/initz - copie.lua diff --git a/DeepSleep/ESP-M3/goodies/rm_files.lua b/DeepSleep/Pet_tracker/goodies/rm_files.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/rm_files.lua rename to DeepSleep/Pet_tracker/goodies/rm_files.lua diff --git a/DeepSleep/ESP-M3/goodies/wifi_ap_start.lua b/DeepSleep/Pet_tracker/goodies/wifi_ap_start.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/wifi_ap_start.lua rename to DeepSleep/Pet_tracker/goodies/wifi_ap_start.lua diff --git a/DeepSleep/ESP-M3/goodies/wifi_ap_stop.lua b/DeepSleep/Pet_tracker/goodies/wifi_ap_stop.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/wifi_ap_stop.lua rename to DeepSleep/Pet_tracker/goodies/wifi_ap_stop.lua diff --git a/DeepSleep/ESP-M3/goodies/wifi_cli_stop.lua b/DeepSleep/Pet_tracker/goodies/wifi_cli_stop.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/wifi_cli_stop.lua rename to DeepSleep/Pet_tracker/goodies/wifi_cli_stop.lua diff --git a/DeepSleep/ESP-M3/goodies/wifi_get_ip.lua b/DeepSleep/Pet_tracker/goodies/wifi_get_ip.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/wifi_get_ip.lua rename to DeepSleep/Pet_tracker/goodies/wifi_get_ip.lua diff --git a/DeepSleep/ESP-M3/goodies/wifi_off.lua b/DeepSleep/Pet_tracker/goodies/wifi_off.lua similarity index 100% rename from DeepSleep/ESP-M3/goodies/wifi_off.lua rename to DeepSleep/Pet_tracker/goodies/wifi_off.lua diff --git a/DeepSleep/ESP-M3/initz.lua b/DeepSleep/Pet_tracker/initz.lua similarity index 100% rename from DeepSleep/ESP-M3/initz.lua rename to DeepSleep/Pet_tracker/initz.lua diff --git a/DeepSleep/ESP-M3/repair.lua b/DeepSleep/Pet_tracker/repair.lua similarity index 100% rename from DeepSleep/ESP-M3/repair.lua rename to DeepSleep/Pet_tracker/repair.lua diff --git a/DeepSleep/ESP-M3/restart.lua b/DeepSleep/Pet_tracker/restart.lua similarity index 100% rename from DeepSleep/ESP-M3/restart.lua rename to DeepSleep/Pet_tracker/restart.lua diff --git a/DeepSleep/ESP-M3/set_time.lua b/DeepSleep/Pet_tracker/set_time.lua similarity index 100% rename from DeepSleep/ESP-M3/set_time.lua rename to DeepSleep/Pet_tracker/set_time.lua diff --git a/DeepSleep/ESP-M3/telnet_srv2.lua b/DeepSleep/Pet_tracker/telnet_srv2.lua similarity index 100% rename from DeepSleep/ESP-M3/telnet_srv2.lua rename to DeepSleep/Pet_tracker/telnet_srv2.lua diff --git a/DeepSleep/ESP-M3/web_ide2.lua b/DeepSleep/Pet_tracker/web_ide2.lua similarity index 100% rename from DeepSleep/ESP-M3/web_ide2.lua rename to DeepSleep/Pet_tracker/web_ide2.lua diff --git a/DeepSleep/ESP-M3/wifi_cli_conf.lua b/DeepSleep/Pet_tracker/wifi_cli_conf.lua similarity index 100% rename from DeepSleep/ESP-M3/wifi_cli_conf.lua rename to DeepSleep/Pet_tracker/wifi_cli_conf.lua diff --git a/DeepSleep/ESP-M3/wifi_cli_start.lua b/DeepSleep/Pet_tracker/wifi_cli_start.lua similarity index 100% rename from DeepSleep/ESP-M3/wifi_cli_start.lua rename to DeepSleep/Pet_tracker/wifi_cli_start.lua diff --git a/DeepSleep/ESP-M3/wifi_info.lua b/DeepSleep/Pet_tracker/wifi_info.lua similarity index 100% rename from DeepSleep/ESP-M3/wifi_info.lua rename to DeepSleep/Pet_tracker/wifi_info.lua diff --git a/DeepSleep/ESP-M3/b.lua b/WIFI_sniffer/b.lua similarity index 68% rename from DeepSleep/ESP-M3/b.lua rename to WIFI_sniffer/b.lua index 1531627..bea73e3 100644 --- a/DeepSleep/ESP-M3/b.lua +++ b/WIFI_sniffer/b.lua @@ -1,21 +1,13 @@ -- 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 zf190119.1710 \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 b.lua zf190119.1804 \n") -- apzuzu6 38:2c:4a:4e:d3:d8 --- S7 b8:d7:af:a6:bd:86 --- maczf 11 5c:f9:38:a1:f7:f0 zmac_adrs={} -zmac_adrs["b8:d7:af:a6:bd:86"]={["zname"]="S7"} +zmac_adrs["b8:d7:af:a6:bd:86"]={["zname"]="S7 zf"} +zmac_adrs["cc:c0:79:7d:f5:d5"]={["zname"]="S7 Mélanie"} zmac_adrs["5c:f9:38:a1:f7:f0"]={["zname"]="maczf"} function zdisp_table() diff --git a/WIFI_sniffer/boot.lua b/WIFI_sniffer/boot.lua new file mode 100644 index 0000000..06e037e --- /dev/null +++ b/WIFI_sniffer/boot.lua @@ -0,0 +1,29 @@ +-- Scripts à charger après le boot pour démarrer son appli + +print("\n boot.lua zf190119.1759 \n") + +function heartbeat() + f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end + boottimer1=tmr.create() + tmr.alarm(boottimer1, 1*1000, tmr.ALARM_AUTO, function() + xfois =2 + blink_LED () + end) +end + +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_srv2.lua" if file.exists(f) then dofile(f) end +f= "web_ide2.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= "b.lua" if file.exists(f) then dofile(f) end + + + +heartbeat() + + + + diff --git a/WIFI_sniffer/flash_led_xfois.lua b/WIFI_sniffer/flash_led_xfois.lua new file mode 100644 index 0000000..c50e5ab --- /dev/null +++ b/WIFI_sniffer/flash_led_xfois.lua @@ -0,0 +1,33 @@ +-- programme pour faire clignoter x fois une LED avec un rapport on/off +print("\n flash_led_xfois.lua zf181208.1521 \n") + +--zLED=0 --NodeMCU +zLED=4 --EPS-M3 +zTm_On_LED = 50 --> en ms +zTm_Off_LED = 100 --> en ms +nbfois = 0 +gpio.write(zLED, gpio.HIGH) +gpio.mode(zLED, gpio.OUTPUT) +ztmr_Flash_LED = tmr.create() + +function blink_LED () + if nbfois >= xfois then +-- print(nbfois) + nbfois = 0 + else + if gpio.read(zLED)==gpio.HIGH then + gpio.write(zLED, gpio.LOW) + tmr.alarm(ztmr_Flash_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED) + else + gpio.write(zLED, gpio.HIGH) + nbfois = nbfois+1 + tmr.alarm(ztmr_Flash_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED) + end + end +end + +xfois =2 +blink_LED () + + + diff --git a/WIFI_sniffer/goodies/a_test_fill.lua b/WIFI_sniffer/goodies/a_test_fill.lua new file mode 100644 index 0000000..b015d37 --- /dev/null +++ b/WIFI_sniffer/goodies/a_test_fill.lua @@ -0,0 +1,30 @@ +-- Scripts juste pour tester des effets à la mano +-- tout sur la couleur: https://www.w3schools.com/colors/default.asp +-- roue des couleurs: https://iro.js.org/?ref=oldsite + +print("\n a_tst_fill.lua zf181125.1632 \n") + +znbled=300 + +function RGB_clear() + ws2812.init() + buffer = ws2812.newBuffer(znbled, 3) + buffer:fill(0, 0, 0) + ws2812.write(buffer) +end + +function RGB_fill(nbled, Red, Green, Blue) + buffer = ws2812.newBuffer(nbled, 3) + buffer:fill(Green, Red, Blue) -- Green, Red , Blue + ws2812.write(buffer) +end + +RGB_clear() +RGB_clear() ; RGB_fill(100, 255, 0, 0) +RGB_clear() ; RGB_fill(100, 0, 255, 0) +RGB_clear() ; RGB_fill(100, 0, 0, 255) +RGB_clear() ; l=0.10 ; R=l*(255) ; G=l*(80*0.99) ; B=l*(0*0.99) ; RGB_fill(300, R, G, B) + + + + diff --git a/WIFI_sniffer/goodies/a_train1.lua b/WIFI_sniffer/goodies/a_train1.lua new file mode 100644 index 0000000..43b4201 --- /dev/null +++ b/WIFI_sniffer/goodies/a_train1.lua @@ -0,0 +1,29 @@ +-- Scripts juste pour tester l'effet train +-- tout sur la couleur: https://www.w3schools.com/colors/default.asp +-- roue des couleurs: https://iro.js.org/?ref=oldsite + +print("\n a_train1.lua zf181204.2004 \n") + +znbled=36 + +function RGB_clear() + ws2812.init() + buffer = ws2812.newBuffer(znbled, 3) + buffer:fill(0, 0, 0) + ws2812.write(buffer) +end + +RGB_clear() + +j=1 +local i, buffer = 0, ws2812.newBuffer(znbled, 3); buffer:fill(0, 0, 0); tmr.create():alarm(20, 1, function() + i = i + j + buffer:fade(2) + buffer:set(i % buffer:size() + 1, 255, 255, 255) + ws2812.write(buffer) + if i>=buffer:size()-1 or i<=0 then + j=j*-1 + end +end) + + diff --git a/WIFI_sniffer/goodies/blink_led1.lua b/WIFI_sniffer/goodies/blink_led1.lua new file mode 100644 index 0000000..43a0e80 --- /dev/null +++ b/WIFI_sniffer/goodies/blink_led1.lua @@ -0,0 +1,23 @@ +-- programme pour faire clignoter une LED avec un rapport on/off + +print("\n blink_led1.lua zf181116.0014 \n") + +zLED=0 +zTm_On_LED = 50 --> en ms +zTm_Off_LED = 500 --> en ms +zFlag_LED = 0 + +function blink_LED () + if zFlag_LED==gpio.LOW then + zFlag_LED=gpio.HIGH + tmr.alarm(ztmr_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED) + else + zFlag_LED=gpio.LOW + tmr.alarm(ztmr_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED) + end + gpio.write(zLED, zFlag_LED) +end + +gpio.mode(zLED, gpio.OUTPUT) +ztmr_LED = tmr.create() +blink_LED () diff --git a/WIFI_sniffer/goodies/blink_led2.lua b/WIFI_sniffer/goodies/blink_led2.lua new file mode 100644 index 0000000..5a0d956 --- /dev/null +++ b/WIFI_sniffer/goodies/blink_led2.lua @@ -0,0 +1,18 @@ +-- programme pour faire clignoter une LED version simplifiée +-- ATTENTION, cela utilise la pin4 pour la LED des module ESP-M3 ! + +print("\n blink_led2.lua zf181208.146 \n") + +zLED=4 +gpio.mode(zLED, gpio.OUTPUT) +ztmr_LED = tmr.create() +value = true + +tmr.alarm(ztmr_LED, 100, tmr.ALARM_AUTO, function () + if value then + gpio.write(zLED, gpio.HIGH) + else + gpio.write(zLED, gpio.LOW) + end + value = not value +end) diff --git a/WIFI_sniffer/goodies/cat.lua b/WIFI_sniffer/goodies/cat.lua new file mode 100644 index 0000000..7c309b9 --- /dev/null +++ b/WIFI_sniffer/goodies/cat.lua @@ -0,0 +1,17 @@ +-- fonction cat() pour afficher le contenu d'un fichier dans la flash +print("\n cat.lua zf180826.1109 \n") + +function cat(zfile) + print("\n"..zfile.."\n-------------------------------") + + zfilei = file.open(zfile, "r") + i=1 + zline=file.readline() + repeat + print(i..": "..string.sub(zline,1,string.len(zline)-1)) + i=i+1 zline=file.readline() + until zline== nil + file.close(zfilei) + + print("-------------------------------") +end diff --git a/WIFI_sniffer/goodies/credentials.lua b/WIFI_sniffer/goodies/credentials.lua new file mode 100644 index 0000000..0efde32 --- /dev/null +++ b/WIFI_sniffer/goodies/credentials.lua @@ -0,0 +1,9 @@ +-- Petit script pour configurer les choses secrètes que l'on n'aimerait +-- pas être exportées sur Internet (github) +-- faut donc le mettre ailleurs que dans le dépôt ! + +print("\n credential.lua zf181205.1910 \n") + +cli_ssid="3g-s7" +cli_pwd="12234567" + diff --git a/WIFI_sniffer/goodies/dir.lua b/WIFI_sniffer/goodies/dir.lua new file mode 100644 index 0000000..8bf9414 --- /dev/null +++ b/WIFI_sniffer/goodies/dir.lua @@ -0,0 +1,15 @@ +-- fonction dir() pour afficher les fichiers dans la flash +print("\n dir.lua zf180826.1019 \n") + +function dir() + print("\n-------------------------------") + l=file.list() i=0 + for k,v in pairs(l) do + i=i+v + print(k..string.rep(" ",19-string.len(k)).." : "..v.." bytes") + end + print("-------------------------------") + print('\nUsed: '..i..' bytes\nusage: dofile("file.lua")\n') +end + +dir() diff --git a/WIFI_sniffer/goodies/flash_led_xfois.lua b/WIFI_sniffer/goodies/flash_led_xfois.lua new file mode 100644 index 0000000..afc4adb --- /dev/null +++ b/WIFI_sniffer/goodies/flash_led_xfois.lua @@ -0,0 +1,32 @@ +-- programme pour faire clignoter x fois une LED avec un rapport on/off +print("\n flash_led_xfois.lua zf181204.1955 \n") + +zLED=0 +zTm_On_LED = 50 --> en ms +zTm_Off_LED = 100 --> en ms +nbfois = 0 +gpio.write(zLED, gpio.HIGH) +gpio.mode(zLED, gpio.OUTPUT) +ztmr_Flash_LED = tmr.create() + +function blink_LED () + if nbfois >= xfois then +-- print(nbfois) + nbfois = 0 + else + if gpio.read(zLED)==gpio.HIGH then + gpio.write(zLED, gpio.LOW) + tmr.alarm(ztmr_Flash_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED) + else + gpio.write(zLED, gpio.HIGH) + nbfois = nbfois+1 + tmr.alarm(ztmr_Flash_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED) + end + end +end + +xfois =2 +blink_LED () + + + diff --git a/WIFI_sniffer/goodies/initz - copie.lua b/WIFI_sniffer/goodies/initz - copie.lua new file mode 100644 index 0000000..80d817d --- /dev/null +++ b/WIFI_sniffer/goodies/initz - copie.lua @@ -0,0 +1,19 @@ +--Script de bootstrap, test au moment du boot qui a été la cause de boot. +-- Si la cause est un power on ou une connexion depuis l'IDE, alors +-- le script repair.lua pendant 30 secondes avant de continuer +--Source: https://nodemcu.readthedocs.io/en/master/en/modules/node/#nodebootreason + +print("\n init.lua zf181125.1340 \n") + +_, reset_reason = node.bootreason() +print("reset_reason:",reset_reason) +if reset_reason == 6 or reset_reason == 6 then + print("seconde chance...") + f= "repair.lua" if file.exists(f) then dofile(f) end + initalarme=tmr.create() + tmr.alarm(initalarme, 8*1000, tmr.ALARM_SINGLE, function() + f= "boot.lua" if file.exists(f) then dofile(f) end + end) +else + f= "boot.lua" if file.exists(f) then dofile(f) end +end diff --git a/WIFI_sniffer/goodies/rm_files.lua b/WIFI_sniffer/goodies/rm_files.lua new file mode 100644 index 0000000..81241cb --- /dev/null +++ b/WIFI_sniffer/goodies/rm_files.lua @@ -0,0 +1,12 @@ +-- pour effacer TOUS les fichiers qui se trouve dans la flash du NodeMCU + +print("\n rm_files.lua zf180907.1511 \n") + + +l=file.list() i=0 +for k,v in pairs(l) do + i=i+v + file.remove(k) +end +print("-------------------------------") +print("\nC'est tout effaced :-) \n") diff --git a/WIFI_sniffer/goodies/wifi_ap_start.lua b/WIFI_sniffer/goodies/wifi_ap_start.lua new file mode 100644 index 0000000..60b5793 --- /dev/null +++ b/WIFI_sniffer/goodies/wifi_ap_start.lua @@ -0,0 +1,14 @@ +-- Démarre le WIFI en mode AP + +print("\n wifi_ap_start.lua zf181119.2359 \n") + +local zmodewifi=wifi.getmode() +if zmodewifi == wifi.NULLMODE then + print("WIFI mode AP only") + wifi.setmode(wifi.SOFTAP) +elseif zmodewifi == wifi.STATION then + print("WIFI mode AP+CLI") + wifi.setmode(wifi.STATIONAP) +end +wifi.ap.config({ ssid = "NodeMCU "..wifi.ap.getmac(), pwd = "12345678" }) +f= "wifi_info.lua" if file.exists(f) then dofile(f) end diff --git a/WIFI_sniffer/goodies/wifi_ap_stop.lua b/WIFI_sniffer/goodies/wifi_ap_stop.lua new file mode 100644 index 0000000..2738627 --- /dev/null +++ b/WIFI_sniffer/goodies/wifi_ap_stop.lua @@ -0,0 +1,10 @@ +-- Démarre le WIFI en mode AP +print("\n wifi_ap_stop.lua zf180824.2000 \n") + +local zmodewifi=wifi.getmode() +if zmodewifi == wifi.SOFTAP then + wifi.setmode(wifi.NULLMODE) +elseif zmodewifi == wifi.STATIONAP then + wifi.setmode(wifi.STATION) +end +print("WIFI AP arrêté") diff --git a/WIFI_sniffer/goodies/wifi_cli_stop.lua b/WIFI_sniffer/goodies/wifi_cli_stop.lua new file mode 100644 index 0000000..9429aa5 --- /dev/null +++ b/WIFI_sniffer/goodies/wifi_cli_stop.lua @@ -0,0 +1,10 @@ +-- Démarre le WIFI en mode AP +print("\n wifi_cli_stop.lua zf180824.2000 \n") + +local zmodewifi=wifi.getmode() +if zmodewifi == wifi.STATION then + wifi.setmode(wifi.NULLMODE) +elseif zmodewifi == wifi.STATIONAP then + wifi.setmode(wifi.SOFTAP) +end +print("WIFI CLI arrêté") diff --git a/WIFI_sniffer/goodies/wifi_get_ip.lua b/WIFI_sniffer/goodies/wifi_get_ip.lua new file mode 100644 index 0000000..82bcdc2 --- /dev/null +++ b/WIFI_sniffer/goodies/wifi_get_ip.lua @@ -0,0 +1,12 @@ +-- Petit script pour obtenir l'adresse IP du NodeMCU connecté sur un AP Wifi +print("\n wifi_get_ip.lua zf181119.2318 \n") + +wifitimer1=tmr.create() +tmr.alarm(wifitimer1, 1000, tmr.ALARM_AUTO , function() + if wifi.sta.getip() == nil then + print("Connecting to AP...") + else + tmr.stop(wifitimer1) + f= "wifi_info.lua" if file.exists(f) then dofile(f) end + end +end) diff --git a/WIFI_sniffer/goodies/wifi_off.lua b/WIFI_sniffer/goodies/wifi_off.lua new file mode 100644 index 0000000..c1c7235 --- /dev/null +++ b/WIFI_sniffer/goodies/wifi_off.lua @@ -0,0 +1,9 @@ +-- Déconnecte le WIFI +print("\n wifi_off.lua zf180822.0959 \n") + +wifi.setmode(wifi.NULLMODE) + +--[[ +print(wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP) +print(wifi.getmode()) +]] diff --git a/WIFI_sniffer/initz.lua b/WIFI_sniffer/initz.lua new file mode 100644 index 0000000..356caa1 --- /dev/null +++ b/WIFI_sniffer/initz.lua @@ -0,0 +1,35 @@ +--Script de bootstrap, test au moment du boot qui a été la cause de boot. +-- Si la cause est un power on ou une connexion depuis l'IDE, alors +-- le script repair.lua pendant xx secondes avant de continuer +--Source: https://nodemcu.readthedocs.io/en/master/en/modules/node/#nodebootreason + +print("\n init.lua zf181210.2358 \n") + +function second_chance() + print("seconde chance...") + f= "repair.lua" if file.exists(f) then dofile(f) end + initalarme=tmr.create() + tmr.alarm(initalarme, 8*1000, tmr.ALARM_SINGLE, function() + f= "boot.lua" if file.exists(f) then dofile(f) end + end) +end + +_, reset_reason = node.bootreason() +print("reset_reason:",reset_reason) +if reset_reason == 0 then + print("power on") + second_chance() +elseif reset_reason == 4 then + print("node.restart") + f= "boot.lua" if file.exists(f) then dofile(f) end +elseif reset_reason == 5 then + print("dsleep wake up") + f= "boot.lua" if file.exists(f) then dofile(f) end +elseif reset_reason == 6 then + print("external reset") + f= "boot.lua" if file.exists(f) then dofile(f) end +else + print("autre raison") + second_chance() +end + diff --git a/WIFI_sniffer/oldies/a.lua b/WIFI_sniffer/oldies/a.lua new file mode 100644 index 0000000..2e94a02 --- /dev/null +++ b/WIFI_sniffer/oldies/a.lua @@ -0,0 +1,40 @@ +-- Scripts pour tester l'écoute des AP WIFI + +print("\n a.lua zf181211.0016 \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 AP list in new format +function a() + ztime() + function listap(t) + print("") + for k,v in pairs(t) do + print(k.." : "..v) + end + print("") + end + wifi.sta.getap(1, listap) +end + +--a() + +--[[ +-- Print AP list that is easier to read +function listap(t) -- (SSID : Authmode, RSSI, BSSID, Channel) + print("\n\t\t\tSSID\t\t\t\t\tBSSID\t\t\t RSSI\t\tAUTHMODE\t\tCHANNEL") + for bssid,v in pairs(t) do + local ssid, rssi, authmode, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]*)") + print(string.format("%32s",ssid).."\t"..bssid.."\t "..rssi.."\t\t"..authmode.."\t\t\t"..channel) + end +end +wifi.sta.getap(1, listap) + + +]] diff --git a/WIFI_sniffer/oldies/a_test_power_wifi.lua b/WIFI_sniffer/oldies/a_test_power_wifi.lua new file mode 100644 index 0000000..a1a9a81 --- /dev/null +++ b/WIFI_sniffer/oldies/a_test_power_wifi.lua @@ -0,0 +1,57 @@ +-- Scripts pour tester la consommation des différents mode du WIFI + +print("\n a_test_power_wifi zf181209.1718 \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("mode physique: ", wifi.getphymode()) +print("defaut mode: ", wifi.getdefaultmode()) +print("wifi stat status: ", wifi.sta.status()) + + +-- print AP list in old format (format not defined) +function listap(t) + for k,v in pairs(t) do + print(k.." : "..v) + end +end +wifi.sta.getap(listap) + +-- Print AP list that is easier to read +function listap(t) -- (SSID : Authmode, RSSI, BSSID, Channel) + print("\n"..string.format("%32s","SSID").."\tBSSID\t\t\t\t RSSI\t\tAUTHMODE\tCHANNEL") + for ssid,v in pairs(t) do + local authmode, rssi, bssid, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]+)") + print(string.format("%32s",ssid).."\t"..bssid.."\t "..rssi.."\t\t"..authmode.."\t\t\t"..channel) + end +end +wifi.sta.getap(listap) + + + + +-- print AP list in new format +function listap(t) + for k,v in pairs(t) do + print(k.." : "..v) + end +end +wifi.sta.getap(1, listap) + +-- Print AP list that is easier to read +function listap(t) -- (SSID : Authmode, RSSI, BSSID, Channel) + print("\n\t\t\tSSID\t\t\t\t\tBSSID\t\t\t RSSI\t\tAUTHMODE\t\tCHANNEL") + for bssid,v in pairs(t) do + local ssid, rssi, authmode, channel = string.match(v, "([^,]+),([^,]+),([^,]+),([^,]*)") + print(string.format("%32s",ssid).."\t"..bssid.."\t "..rssi.."\t\t"..authmode.."\t\t\t"..channel) + end +end +wifi.sta.getap(1, listap) + + diff --git a/WIFI_sniffer/oldies/dsleep.lua b/WIFI_sniffer/oldies/dsleep.lua new file mode 100644 index 0000000..14453b3 --- /dev/null +++ b/WIFI_sniffer/oldies/dsleep.lua @@ -0,0 +1,64 @@ +-- Teste le deep sleep ! +-- s'endore pendant xx secondes après xx secondes + +-- ATTENTION: il faut connecter la pin 0 à la pin RESET avec une résistance de 1k ! + +print("\n dsleep.lua zf181211.0018 \n") + +f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end + +function dsleep_on() + print("timer dsleep on...") + ztmr_SLEEP = tmr.create() + tmr.alarm(ztmr_SLEEP, 10*1000, tmr.ALARM_SINGLE, function () + print("Je dors...") + tmr.delay(100*1000) +-- node.dsleep(4*1000*1000) + rtctime.dsleep(30*1000*1000) + end) +end + +function dsleep_off() + print("timer dsleep off...") + tmr.unregister(ztmr_SLEEP) +end + +function watch_wifi_on() + dsleep_on() + ztmr_watch_wifi_on=tmr.create() + tmr.alarm(ztmr_watch_wifi_on, 1000, tmr.ALARM_AUTO , function() + if wifi.sta.getip() == nil then +-- print("Unconnected... (on)") + else + tmr.stop(ztmr_watch_wifi_on) + print("Connected... (on)") +-- f= "wifi_info.lua" if file.exists(f) then dofile(f) end + watch_wifi_off() + end + end) +end + +function watch_wifi_off() + dsleep_off() + tmr.unregister(ztmr_watch_wifi_on) + ztmr_watch_wifi_off=tmr.create() + tmr.alarm(ztmr_watch_wifi_off, 1000, tmr.ALARM_AUTO , function() + if wifi.sta.getip() == nil then + tmr.stop(ztmr_watch_wifi_off) + print("Unconnected... (off)") + watch_wifi_on() + tmr.unregister(ztmr_watch_wifi_off) + else +-- print("Connected... (off)") + xfois =2 + blink_LED () + end + end) +end + +print("Coucou, je suis réveillé...") +print("Et il est: ") +ztime() + +watch_wifi_on() + diff --git a/WIFI_sniffer/repair.lua b/WIFI_sniffer/repair.lua new file mode 100644 index 0000000..691c123 --- /dev/null +++ b/WIFI_sniffer/repair.lua @@ -0,0 +1,16 @@ +-- Scripts de seconde chance pour réparer une boucle dans le restart + +print("\n repair.lua zf181210.1456 \n") + +--f= "wifi_ap_start.lua" if file.exists(f) then dofile(f) end +--f= "telnet_srv.lua" if file.exists(f) then dofile(f) end + +--f= "az_init_led.lua" if file.exists(f) then dofile(f) end + + +--[[ +jobtimer1=tmr.create() +tmr.alarm(jobtimer1, 5*1000, tmr.ALARM_AUTO, function() + print("repair...") +end) +]] diff --git a/WIFI_sniffer/restart.lua b/WIFI_sniffer/restart.lua new file mode 100644 index 0000000..85f28eb --- /dev/null +++ b/WIFI_sniffer/restart.lua @@ -0,0 +1,12 @@ +-- Scripts pour faire un soft reset + +print("\n restart.lua zf181209.1753 \n") + +restarttimer1=tmr.create() +tmr.alarm(restarttimer1, 2*1000, tmr.ALARM_SINGLE, function() + node.restart() +end) + +print("hello zuzu") + + diff --git a/WIFI_sniffer/set_time.lua b/WIFI_sniffer/set_time.lua new file mode 100644 index 0000000..71bea27 --- /dev/null +++ b/WIFI_sniffer/set_time.lua @@ -0,0 +1,24 @@ +-- Scripts pour régler l'horloge quand on est connecté en WIFI + +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 + + + +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"])) +end + +set_time() +ztime() diff --git a/WIFI_sniffer/telnet_srv2.lua b/WIFI_sniffer/telnet_srv2.lua new file mode 100644 index 0000000..821358c --- /dev/null +++ b/WIFI_sniffer/telnet_srv2.lua @@ -0,0 +1,87 @@ +-- Serveur telnet pour connexion en remote WIFI, NOUVELLE VERSION ! +-- source: https://github.com/nodemcu/nodemcu-firmware/blob/master/lua_examples/telnet/telnet.lua + +print("\n telnet_srv2.lua zf181215.1326 \n") + +local node, table, tmr, wifi, uwrite, tostring = + node, table, tmr, wifi, uart.write, tostring + +local function telnet_listener(socket) + local insert, remove, concat, heap, gc = + table.insert, table.remove, table.concat, node.heap, collectgarbage + local fifo1, fifo1l, fifo2, fifo2l = {}, 0, {}, 0 + local s -- s is a copy of the TCP socket if and only if sending is in progress + local wdclr, cnt = tmr.wdclr, 0 + local function debug(fmt, ...) + if (...) then fmt = fmt:format(...) end + uwrite(0, "\r\nDBG: ",fmt,"\r\n" ) + cnt = cnt + 1 + if cnt % 10 then wdclr() end + end + + local function flushGarbage() + if heap() < 13440 then gc() end + end + + local function sendLine() + if not s then return end + + if fifo2l + fifo1l == 0 then -- both FIFOs empty, so clear down s + s = nil + return + end + flushGarbage() + if #fifo2 < 4 then -- Flush FIFO1 into FIFO2 + insert(fifo2,concat(fifo1)) + fifo2l, fifo1, fifo1l = fifo2l + fifo1l, {}, 0 + end + local rec = remove(fifo2,1) .. (remove(fifo2,1) or '') .. + (remove(fifo2,1) or '') .. (remove(fifo2,1) or '') + fifo2l = fifo2l - #rec + flushGarbage() + s:send(rec) + end + + local F1_SIZE = 256 + + local function queueLine(str) + while #str > 0 do -- this is because str might be longer than the packet size! + local k, l = F1_SIZE - fifo1l, #str + local chunk + if #fifo1 >= 32 or (k < l and k < 16) then + insert(fifo2, concat(fifo1)) + fifo2l, fifo1, fifo1l, k = fifo2l + fifo1l, {}, 0, F1_SIZE + end + if l > k+16 then -- also tolerate a size overrun of 16 bytes to avoid a split + chunk, str = str:sub(1,k), str:sub(k+1) + else + chunk, str = str, '' + end + insert(fifo1, chunk) + fifo1l = fifo1l + #chunk + end + if not s and socket then + s = socket + sendLine() + else + flushGarbage() + end + end + + local function receiveLine(s, line) + node.input(line) + end + + local function disconnect(s) + fifo1, fifo1l, fifo2, fifo2l, s = {}, 0, {}, 0, nil + node.output(nil) + end + + socket:on("receive", receiveLine) + socket:on("disconnection", disconnect) + socket:on("sent", sendLine) + node.output(queueLine, 0) +end + +net.createServer(net.TCP, 180):listen(23, telnet_listener) +print("Telnet server running...\nUsage: telnet -rN ip\n") diff --git a/WIFI_sniffer/web_ide2.lua b/WIFI_sniffer/web_ide2.lua new file mode 100644 index 0000000..16d00f2 --- /dev/null +++ b/WIFI_sniffer/web_ide2.lua @@ -0,0 +1,159 @@ +-- Petit WEB IDE tout simple autonome +-- ATTENTION: tourne sur le port 88 ! + +print("\n _web_ide2.lua zf181210.1516 \n") + +--[[ +XChip's NodeMCU IDE + +Create, Edit and run NodeMCU files using your webbrowser. +Examples: +http:/// will list all the files in the MCU +http:///newfile.lua displays the file on your browser +http:///newfile.lua?edit allows to creates or edits the specified script in your browser +http:///newfile.lua?run it will run the specified script and will show the returned value +]]-- + +srv=net.createServer(net.TCP) +srv:listen(88,function(conn) + + local rnrn=0 + local Status = 0 + local DataToGet = 0 + local method="" + local url="" + local vars="" + + conn:on("receive",function(conn,payload) + + if Status==0 then + _, _, method, url, vars = string.find(payload, "([A-Z]+) /([^?]*)%??(.*) HTTP") + print(method, url, vars) + end + + if method=="POST" then + + if Status==0 then + --print("status", Status) + _,_,DataToGet, payload = string.find(payload, "Content%-Length: (%d+)(.+)") + if DataToGet~=nil then + DataToGet = tonumber(DataToGet) + --print(DataToGet) + rnrn=1 + Status = 1 + else + print("bad length") + end + end + + -- find /r/n/r/n + if Status==1 then + --print("status", Status) + local payloadlen = string.len(payload) + local mark = "\r\n\r\n" + local i + for i=1, payloadlen do + if string.byte(mark, rnrn) == string.byte(payload, i) then + rnrn=rnrn+1 + if rnrn==5 then + payload = string.sub(payload, i+1,payloadlen) + file.open(url, "w") + file.close() + Status=2 + break + end + else + rnrn=1 + end + end + if Status==1 then + return + end + end + + if Status==2 then + --print("status", Status) + if payload~=nil then + DataToGet=DataToGet-string.len(payload) + --print("DataToGet:", DataToGet, "payload len:", string.len(payload)) + file.open(url, "a+") + file.write(payload) + file.close() + else + conn:send("HTTP/1.1 200 OK\r\n\r\nERROR") + Status=0 + end + + if DataToGet==0 then + conn:send("HTTP/1.1 200 OK\r\n\r\nOK") + Status=0 + end + end + + return + end + + DataToGet = -1 + + if url == "favicon.ico" then + conn:send("HTTP/1.1 404 file not found") + return + end + + conn:send("HTTP/1.1 200 OK\r\n\r\n") + + -- it wants a file in particular + if url~="" and vars=="" then + DataToGet = 0 + return + end + + conn:send("

NodeMCU IDE

") + + if vars=="edit" then + conn:send("") + conn:send("

Back to file list\n") + conn:send("

run") + conn:send("



") + end + + if vars=="run" then + conn:send("") + local st, result=pcall(dofile, url) + conn:send(tostring(result)) + conn:send("") + end + + if url=="" then + local l = file.list(); + for k,v in pairs(l) do + conn:send(""..k..", size:"..v.."
") + end + end + + conn:send("") + + end) + conn:on("sent",function(conn) + if DataToGet>=0 and method=="GET" then + if file.open(url, "r") then + file.seek("set", DataToGet) + local line=file.read(512) + file.close() + if line then + conn:send(line) + DataToGet = DataToGet + 512 + + if (string.len(line)==512) then + return + end + end + end + end + + conn:close() + end) +end) +print("listening, free:", node.heap()) + diff --git a/WIFI_sniffer/wifi_cli_conf.lua b/WIFI_sniffer/wifi_cli_conf.lua new file mode 100644 index 0000000..6726313 --- /dev/null +++ b/WIFI_sniffer/wifi_cli_conf.lua @@ -0,0 +1,12 @@ +-- Petit script pour configurer le client WIFI du NodeMCU + +print("\n wifi_cli_conf.lua zf181205.1931 \n") + +--credentials par défaut +cli_ssid="3g-s7" +cli_pwd="12234567" + +--ses propre credentials +f= "credentials.lua" if file.exists(f) then dofile(f) end + +wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, save=true} diff --git a/WIFI_sniffer/wifi_cli_start.lua b/WIFI_sniffer/wifi_cli_start.lua new file mode 100644 index 0000000..f1091ac --- /dev/null +++ b/WIFI_sniffer/wifi_cli_start.lua @@ -0,0 +1,14 @@ +-- Petit script pour connecter le NodeMCU sur un AP Wifi avec l'accompte sauvé en EEPROM +print("\n wifi_cli_start.lua zf181119.2359 \n") + +local zmodewifi=wifi.getmode() +if zmodewifi == wifi.NULLMODE then + print("WIFI mode CLI only") + wifi.setmode(wifi.STATION) +elseif zmodewifi == wifi.SOFTAP then + print("WIFI mode AP+CLI") + wifi.setmode(wifi.STATIONAP) +end +wifi.sta.autoconnect(1) +wifi.sta.connect() +f= "wifi_get_ip.lua" if file.exists(f) then dofile(f) end diff --git a/WIFI_sniffer/wifi_info.lua b/WIFI_sniffer/wifi_info.lua new file mode 100644 index 0000000..5062fcf --- /dev/null +++ b/WIFI_sniffer/wifi_info.lua @@ -0,0 +1,31 @@ +-- Petit script pour afficher les infos actuel du WIFI +print("\n wifi_info.lua zf181119.0014 \n") + +local zmodewifi=wifi.getmode() + +--wifi.NULLMODE, wifi.STATION, wifi.SOFTAP, wifi.STATIONAP + +if zmodewifi == wifi.NULLMODE then + print("WIFI OFF") +elseif zmodewifi == wifi.STATION then + print("WIFI mode CLI") + print("Connected IP:\n",wifi.sta.getip()) + do + local sta_config=wifi.sta.getconfig(true) + print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false"))) + end +elseif zmodewifi == wifi.SOFTAP then + print("WIFI mode AP") + print("AP MAC:\n",wifi.ap.getmac()) + print("AP IP:\n",wifi.ap.getip()) + print("AP Connect:\n",wifi.ap.getconfig()) +elseif zmodewifi == wifi.STATIONAP then + print("WIFI mode CLI+AP") + print("Connected IP:\n",wifi.sta.getip()) + do + local sta_config=wifi.sta.getconfig(true) + print(string.format("Current client config:\n\tssid:\"%s\"\tpassword:\"%s\"\n\tbssid:\"%s\"\tbssid_set:%s", sta_config.ssid, sta_config.pwd, sta_config.bssid, (sta_config.bssid_set and "true" or "false"))) + end + print("AP MAC: "..wifi.ap.getmac()) + print("AP IP: "..wifi.ap.getip()) +end