Complètement refactorisé la partie initialisation du WIFI au boot. On ne l'initialise PLUS au moment du boot !
This commit is contained in:
93
WIFI_sniffer/cret_project/README.md
Normal file
93
WIFI_sniffer/cret_project/README.md
Normal file
@@ -0,0 +1,93 @@
|
||||
# Remise au goût du jour le petit script luatool.py
|
||||
|
||||
## Sources
|
||||
https://github.com/4refr0nt/luatool
|
||||
|
||||
|
||||
## Description
|
||||
Le petit script python *luatool.py* permet d'automatiser le téléchargement de
|
||||
scripts *.lua* sur un NodeMCU branché sur le port USB.<br>
|
||||
Mais il permet aussi et surtout de le faire via WIFI. Pour cela il faut que le petit serveur *telnet* tourne sur le NodeMCU !
|
||||
|
||||
|
||||
## Problématiques
|
||||
La version actuelle datant de juillet 2017 ne fonctionne plus avec les nouveaux firmwares de NodeMCU. Il a y un problème au moment de l'initialisation de la connexion série.
|
||||
|
||||
|
||||
## Travail effectué
|
||||
* J'ai donc repris le code python et juste après l'initialisation du port série je cherche le caractère '>', ainsi je suis certain que le NodeMCU a bien redémarré.
|
||||
|
||||
* J'ai aussi diminué le délai d'attente entre chaque ligne, passé de 0.3 sec à 0.03 sec. Les téléchargements sont donc 10x plus rapides
|
||||
|
||||
* J'ai aussi mis un nouveau telnet serveur qui tient compte des tailles maximales des paquets TCP
|
||||
|
||||
* J'ai aussi bien amélioré le script luatool.py (voir le code source)
|
||||
|
||||
|
||||
## Installation
|
||||
Maintenant c'est très facile de télécharger tout un projet sur un NodeMCU. Il suffit simplement de modifier le petit script bash upload.sh, puis de faire:
|
||||
|
||||
```
|
||||
./upload.sh
|
||||
```
|
||||
* A chaque utilisation de luatool.py, le NodeMCU, s'il est branché sur le port série, redémarre !
|
||||
* S'il y a des erreurs lors d'un téléchargement, il faut simplement augmenter un peu le délai !<br>
|
||||
* Il est préférable de télécharger en premier les *gros* fichiers .lua !
|
||||
|
||||
|
||||
## Test via WIFI en telnet
|
||||
Après avoir installé tout le *binz* sur le NodeMCU avec le script *upload.sh*, on peut utiliser *luatool.py* via le WIFI.<br>
|
||||
On peut le tester avec le petit script:
|
||||
```
|
||||
./test_toto-sh
|
||||
```
|
||||
|
||||
* Si cela fonctionne, la LED devrait arrêter de clignoter ;-)
|
||||
|
||||
|
||||
## Goodies
|
||||
### Quelques commandes en WIFI ;-)
|
||||
**ATTENTION:** ces exemples de commandes sont pour MON adresse IP actuelle de mon NodeMCU ;-)
|
||||
|
||||
Help du luatool.py
|
||||
```
|
||||
./luatool.py -h
|
||||
```
|
||||
|
||||
Liste les fichiers qui se trouvent sur le NodeMCU
|
||||
```
|
||||
./luatool.py --ip 192.168.0.157 -l
|
||||
```
|
||||
|
||||
Télécharge le fichier *toto.lua* sur le NodeMCU
|
||||
```
|
||||
./luatool.py --ip 192.168.0.157 -f toto.lua
|
||||
```
|
||||
|
||||
Télécharge le fichier *toto.lua* sur le NodeMCU, mais le renomme en *tutu.lua* et affiche une *progression bar* de l'évolution du téléchargement
|
||||
```
|
||||
./luatool.py --ip 192.168.0.157 -f toto.lua -t tutu.lua
|
||||
```
|
||||
|
||||
Vérifie que tout est bon sur le NodeMCU
|
||||
```
|
||||
./luatool.py --ip 192.168.0.157 -l
|
||||
```
|
||||
|
||||
Efface le fichier *toto.lua* sur le NodeMCU
|
||||
```
|
||||
./luatool.py --ip 192.168.0.157 --delete toto.lua
|
||||
```
|
||||
|
||||
Efface le fichier *tutu.lua* sur le NodeMCU
|
||||
```
|
||||
./luatool.py --ip 192.168.0.157 --delete tutu.lua
|
||||
```
|
||||
|
||||
Vérifie que tout est bon sur le NodeMCU
|
||||
```
|
||||
./luatool.py --ip 192.168.0.157 -l
|
||||
```
|
||||
|
||||
|
||||
zf191021.1619
|
||||
19
WIFI_sniffer/cret_project/_secrets_energy.lua_
Normal file
19
WIFI_sniffer/cret_project/_secrets_energy.lua_
Normal file
@@ -0,0 +1,19 @@
|
||||
-- Petit script pour configurer les choses secrètes que l'on n'aimerait
|
||||
-- pas être exportées sur Internet (github)
|
||||
-- donc on ne met PAS des secrets dans le code !
|
||||
-- faut le mettre ailleurs que dans le dépôt !
|
||||
-- il faut le renommer en 'secrets_energy.lua' et sera exécuté
|
||||
-- par 'boot.lua' au moment du boot
|
||||
|
||||
function secrets()
|
||||
print("\n secrets_energy.lua zf190916.1458 \n")
|
||||
|
||||
cli_ssid="xxx"
|
||||
cli_pwd="xxx"
|
||||
|
||||
influxdb_url="http://xxx.yyy.zzz:8086/write?db=xxx&u=admin&p=xxx"
|
||||
print("influxdb_url: "..influxdb_url)
|
||||
|
||||
end
|
||||
secrets()
|
||||
secrets=nil
|
||||
102
WIFI_sniffer/cret_project/_zremote_cmd.txt
Normal file
102
WIFI_sniffer/cret_project/_zremote_cmd.txt
Normal file
@@ -0,0 +1,102 @@
|
||||
# Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom
|
||||
# zf191029.1645
|
||||
|
||||
# si luatool ne marche pas sur le MAC, il faut lire ceci:
|
||||
# https://docs.google.com/document/d/1q64uK3IMOgEDdKaIAttbYuFt4GuLQ06k3FLeyfCsWLg/edit#heading=h.bmefcu67uwj0
|
||||
|
||||
# raccourcis clavier
|
||||
# CTRL+ALT+ENTER envoie au terminal la ligne de l'éditeur
|
||||
# SHIT+CTRL+` ouvre le terminal (attention, ne pas oublier de copier le *path* dans le *tree* et le changer)
|
||||
# ALT+CMD+F bascule entre le terminal et l'éditeur
|
||||
|
||||
# définitions à faire AVANT !
|
||||
export luatool_tty="/dev/cu.wchusbserial1410"
|
||||
export zIP="localhost"
|
||||
export zport="2323"
|
||||
ATTENTION: voir les tunnels tout à la fin !
|
||||
|
||||
|
||||
# ouvrir et fermer (ALT+N+.) une session telnet sur le NodeMCU avec l'adresse zIP)
|
||||
telnet -rN $zIP $zport
|
||||
~.
|
||||
node.restart()
|
||||
=node.heap()
|
||||
|
||||
|
||||
# commandes lua pour ce projet
|
||||
verbose=true
|
||||
verbose=false
|
||||
|
||||
|
||||
#commandes luatool pour ce projet
|
||||
./luatool.py --ip $zIP:$zport -l
|
||||
|
||||
./luatool.py --ip $zIP:$zport -f b.lua
|
||||
./luatool.py --ip $zIP:$zport -f web_srv2.lua
|
||||
./luatool.py --ip $zIP:$zport -f z_index.html
|
||||
./luatool.py --ip $zIP:$zport -f z_page1.html
|
||||
./luatool.py --ip $zIP:$zport -f z_page2.html
|
||||
./luatool.py --ip $zIP:$zport -f z_page3.html
|
||||
./luatool.py --ip $zIP:$zport -f z_page4.html
|
||||
./luatool.py --ip $zIP:$zport -f wifi_ap_start.lua
|
||||
./luatool.py --ip $zIP:$zport -f boot2.lua
|
||||
|
||||
dofile("wifi_ap_start.lua")
|
||||
dofile("wifi_info.lua")
|
||||
node.restart()
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
|
||||
|
||||
|
||||
~.
|
||||
./luatool.py --ip $zIP:$zport -f b.lua
|
||||
telnet -rN $zIP $zport
|
||||
dofile("b.lua")
|
||||
zshow()
|
||||
|
||||
|
||||
|
||||
|
||||
~.
|
||||
./luatool.py --ip $zIP:$zport -f head.lua
|
||||
telnet -rN $zIP $zport
|
||||
dofile("head.lua")
|
||||
zhead("telnet_srv2.lua")
|
||||
|
||||
|
||||
./luatool.py --ip $zIP --zrestart
|
||||
|
||||
|
||||
# faire un cat d'un fichier sur le NodeMCU
|
||||
dofile("cat.lua")
|
||||
cat("boot2.lua")
|
||||
|
||||
|
||||
# commandes luatool
|
||||
./luatool.py -h
|
||||
./luatool.py --ip $zIP:$zport -i
|
||||
./luatool.py --ip $zIP:$zport -l
|
||||
./luatool.py --ip $zIP:$zport -f toto.lua -d
|
||||
./luatool.py --ip $zIP:$zport --delete toto.lua
|
||||
|
||||
|
||||
# création des tunnels ssh
|
||||
ATTENTION: dans un premier terminal !
|
||||
Pour le MsL
|
||||
ssh -t -L 2323:localhost:2323 ubuntu@www.zuzutest.ml ssh -N -L 2323:192.168.1.111:23 ubuntu@localhost -p 20221
|
||||
|
||||
Pour le Crêt
|
||||
ssh -N -L 2323:192.168.0.137:23 admin@z.zufferey.com -p 1822
|
||||
|
||||
ATTENTION: dans un deuxième terminal !
|
||||
export zIP="localhost"
|
||||
export zport="2323"
|
||||
telnet -rN $zIP $zport
|
||||
~.
|
||||
node.restart()
|
||||
=node.heap()
|
||||
|
||||
|
||||
|
||||
|
||||
.
|
||||
176
WIFI_sniffer/cret_project/b.lua
Normal file
176
WIFI_sniffer/cret_project/b.lua
Normal file
@@ -0,0 +1,176 @@
|
||||
-- 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 zf191029.1944 \n")
|
||||
|
||||
--f= "set_time.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
-- apzuzu6 38:2c:4a:4e:d3:d8
|
||||
|
||||
zmac_adrs={}
|
||||
zmac_adrs[#zmac_adrs+1]="b8:d7:af:a6:bd:86,S7 zf,0,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="cc:c0:79:7d:f5:d5,S7 Melanie,0,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="5c:f9:38:a1:f7:f0,MAC zf,0,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="d8:30:62:5a:d6:3a,IMAC Maman,0,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="88:e9:fe:6b:ec:1e,MAC Luc,0,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="0c:2c:54:b3:c5:1a,HU Nicolas,0,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="c0:a6:00:bf:4e:43,IPHONE Maeva,0,0,0"
|
||||
--[[
|
||||
zmac_adrs[#zmac_adrs+1]="80:58:f8:44:09:ce, ,-30,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="02:07:49:35:67:10, ,-58,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="c0:ee:fb:4a:ff:28, ,-55,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="da:a1:19:ed:93:84, ,-59,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="02:c5:a0:96:05:bd, ,-32,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="da:a1:19:a6:a0:93, ,-56,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="46:79:22:70:f5:b8, ,-59,0,0"
|
||||
zmac_adrs[#zmac_adrs+1]="86:27:18:64:f8:c0, ,-57,0,0"
|
||||
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()
|
||||
print("coucou")
|
||||
for i=1, #zmac_adrs do
|
||||
-- print(i,zmac_adrs[i])
|
||||
zadrs, zname, zrssi, ztime0, ztime1 = zmac_adrs[i]:match("([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)")
|
||||
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
|
||||
|
||||
function zsplit(zline)
|
||||
zadrs, zname, zrssi, ztime0, ztime1 = zline:match("([^,]+),([^,]+),([^,]+),([^,]+),([^,]+)")
|
||||
-- print("-", zadrs, zname, zrssi, ztime0, ztime1,"-")
|
||||
end
|
||||
|
||||
function zmerge()
|
||||
zline=zadrs..","..zname..","..zrssi..","..ztime0..","..ztime1
|
||||
return zline
|
||||
end
|
||||
|
||||
function find_adrs(zadrs)
|
||||
for i=1, #zmac_adrs do
|
||||
if zadrs == zmac_adrs[i]:match("([^,]+),[^,]+,[^,]+,[^,]+,[^,]+") then
|
||||
-- print("find: "..zmac_adrs[i])
|
||||
return i
|
||||
end
|
||||
end
|
||||
return 1-1
|
||||
end
|
||||
|
||||
function zsort_rssi()
|
||||
print("tri du tableau")
|
||||
table.sort(zmac_adrs, function(a,b)
|
||||
return a:match("[^,]+,[^,]+,([^,]+),[^,]+,[^,]+") < b:match("[^,]+,[^,]+,([^,]+),[^,]+,[^,]+")
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
|
||||
--[[
|
||||
zshow()
|
||||
zsort_rssi()
|
||||
|
||||
zsplit(zmac_adrs[1])
|
||||
print(zmerge())
|
||||
|
||||
print(find_adrs("88:e9:fe:6b:ec:1e"))
|
||||
print(find_adrs("da:a1:19:b6:6b:50"))
|
||||
|
||||
print(find_adrs("88:e9:fe:6b:ec:1e"))
|
||||
zsplit(zmac_adrs[5])
|
||||
zrssi=-45 ztime0="10:19" ztime1="10:19"
|
||||
zmac_adrs[5]=zmerge()
|
||||
print(find_adrs("88:e9:fe:6b:ec:1e"))
|
||||
|
||||
zmac_adrs=nil
|
||||
zmac_adrs={}
|
||||
|
||||
]]
|
||||
|
||||
function zround(num, dec)
|
||||
local mult = 10^(dec or 0)
|
||||
return math.floor(num * mult + 0.5) / mult
|
||||
end
|
||||
|
||||
|
||||
|
||||
--zadrs, zname, zrssi, ztime0, ztime1
|
||||
|
||||
function zsniff(T)
|
||||
print("toto1950: "..T.RSSI)
|
||||
if T.RSSI > -100 then
|
||||
print("\n\tMAC: ".. T.MAC.."\n\tRSSI: "..T.RSSI)
|
||||
-- ztime()
|
||||
z_adrs_mac_index=find_adrs(T.MAC)
|
||||
print("toto: -"..z_adrs_mac_index.."-")
|
||||
if z_adrs_mac_index == 0 then
|
||||
print("Oh une inconnue !")
|
||||
zmac_adrs[#zmac_adrs+1]=" , ,0,0,0"
|
||||
z_adrs_mac_index=#zmac_adrs
|
||||
-- print("tutu: -"..zmac_adrs[z_adrs_mac_index].."-")
|
||||
zsplit(zmac_adrs[z_adrs_mac_index])
|
||||
zadrs=T.MAC
|
||||
else
|
||||
-- print("titi: -")
|
||||
zsplit(zmac_adrs[z_adrs_mac_index])
|
||||
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
|
||||
zrssi=T.RSSI
|
||||
else
|
||||
zrssi=zround((4*zrssi+T.RSSI)/5, 0)
|
||||
end
|
||||
]]
|
||||
if zname ~= " " then
|
||||
print("Bonjour "..zname.." ! "..zrssi)
|
||||
end
|
||||
zmac_adrs[z_adrs_mac_index]=zmerge()
|
||||
end
|
||||
end
|
||||
|
||||
function zcalc_distance(zrssi2)
|
||||
zrssi_1m=-40 zn=2
|
||||
zdist=10^((zrssi_1m - zrssi2) / (10 * zn))
|
||||
return zdist
|
||||
end
|
||||
|
||||
--[[
|
||||
print("distance: "..zcalc_distance(-60).."m")
|
||||
|
||||
La formule pour calculer la distance est assez simple.
|
||||
|
||||
d = 10 ^ ((TxPower - RSSI) / (10 * n))
|
||||
|
||||
- TxPower est le RSSI mesuré à 1 m d'un point d'accès connu. Par exemple: -84 dB.
|
||||
- n est la constante de propagation ou l'exposant d'affaiblissement de trajet. Par exemple: 2,7 à 4,3 (l'espace libre a n = 2 pour référence).
|
||||
- RSSI est le RSSI mesuré
|
||||
- d est la distance en mètre
|
||||
]]
|
||||
|
||||
|
||||
wifi.eventmon.register(wifi.eventmon.AP_PROBEREQRECVED, zsniff)
|
||||
|
||||
--[[
|
||||
|
||||
wifi.eventmon.unregister(wifi.eventmon.AP_PROBEREQRECVED)
|
||||
zsort_rssi() zshow()
|
||||
|
||||
]]
|
||||
9
WIFI_sniffer/cret_project/boot.lua
Normal file
9
WIFI_sniffer/cret_project/boot.lua
Normal file
@@ -0,0 +1,9 @@
|
||||
-- Scripts à charger après le boot pour démarrer le core system
|
||||
|
||||
print("\n boot.lua zf191029.2114 \n")
|
||||
|
||||
|
||||
--f= "led_rgb.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
|
||||
--ff= "web_srv2.lua" if file.exists(f) then dofile(f) end
|
||||
40
WIFI_sniffer/cret_project/boot2.lua
Normal file
40
WIFI_sniffer/cret_project/boot2.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
-- Scripts à charger après le boot pour démarrer son projet
|
||||
|
||||
print("\n boot2.lua zf191029.2154 \n")
|
||||
|
||||
second_chance=nil
|
||||
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
xfois =5 blink_LED ()
|
||||
|
||||
function heartbeat()
|
||||
boottimer1=tmr.create()
|
||||
boottimer1:alarm(1*1000, tmr.ALARM_AUTO, function()
|
||||
xfois =2
|
||||
blink_LED ()
|
||||
end)
|
||||
end
|
||||
|
||||
-- charge ses propres secrets
|
||||
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
f= "set_time.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
|
||||
|
||||
f=nil
|
||||
|
||||
tmr.create():alarm(4*1000, tmr.ALARM_SINGLE, function()
|
||||
flash_led_xfois=nil blink_LED=nil ztmr_Flash_LED=nil
|
||||
zTm_Off_LED=nil zTm_On_LED=nil nbfois=nil xfois=nil zLED=nil
|
||||
end)
|
||||
|
||||
heartbeat=nil
|
||||
--heartbeat()
|
||||
|
||||
--[[
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
|
||||
|
||||
]]
|
||||
|
||||
18
WIFI_sniffer/cret_project/cat.lua
Normal file
18
WIFI_sniffer/cret_project/cat.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
-- fonction cat() pour afficher le contenu d'un fichier dans la flash
|
||||
print("\n cat.lua zf192026.0858 \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))
|
||||
print(string.sub(zline,1,string.len(zline)-1))
|
||||
i=i+1 zline=file.readline()
|
||||
until zline== nil
|
||||
file.close(zfilei)
|
||||
|
||||
print("-------------------------------")
|
||||
end
|
||||
15
WIFI_sniffer/cret_project/dir.lua
Normal file
15
WIFI_sniffer/cret_project/dir.lua
Normal file
@@ -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()
|
||||
40
WIFI_sniffer/cret_project/flash_led_xfois.lua
Normal file
40
WIFI_sniffer/cret_project/flash_led_xfois.lua
Normal file
@@ -0,0 +1,40 @@
|
||||
-- programme pour faire clignoter x fois une LED avec un rapport on/off
|
||||
|
||||
function flash_led_xfois()
|
||||
print("\n flash_led_xfois.lua zf191029.2111 \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)
|
||||
ztmr_Flash_LED:alarm(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)
|
||||
ztmr_Flash_LED:alarm(zTm_On_LED, tmr.ALARM_SINGLE, blink_LED)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
flash_led_xfois()
|
||||
|
||||
--[[
|
||||
xfois =2
|
||||
blink_LED ()
|
||||
]]
|
||||
19
WIFI_sniffer/cret_project/head.lua
Normal file
19
WIFI_sniffer/cret_project/head.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
-- fonction cat() pour afficher les 10 premières lignes d'un fichier dans la flash
|
||||
print("\n head.lua zf192028.1516 \n")
|
||||
|
||||
function zhead(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))
|
||||
print(string.sub(zline,1,string.len(zline)-1))
|
||||
i=i+1 zline=file.readline()
|
||||
if i>10 then break end
|
||||
until zline==nil
|
||||
file.close(zfilei)
|
||||
|
||||
print("-------------------------------")
|
||||
end
|
||||
63
WIFI_sniffer/cret_project/initz.lua
Normal file
63
WIFI_sniffer/cret_project/initz.lua
Normal file
@@ -0,0 +1,63 @@
|
||||
--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 zf190917.0001 \n")
|
||||
|
||||
zswitch=3 --switch flash
|
||||
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
|
||||
|
||||
function hvbouton()
|
||||
gpio.trig(zswitch, "none")
|
||||
initalarme:unregister() initalarme2:unregister()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
end
|
||||
|
||||
gpio.trig(zswitch, "both", hvbouton)
|
||||
|
||||
function second_chance()
|
||||
print("seconde chance...")
|
||||
f= "repair.lua" if file.exists(f) then dofile(f) end
|
||||
initalarme=tmr.create()
|
||||
initalarme:alarm(4*1000, tmr.ALARM_SINGLE, function()
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
end)
|
||||
initalarme2=tmr.create()
|
||||
initalarme2:alarm(30*1000, tmr.ALARM_SINGLE, function()
|
||||
gpio.trig(zswitch)
|
||||
hvbouton=nil
|
||||
zswitch=nil
|
||||
reset_reason=nil
|
||||
f= "boot2.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")
|
||||
gpio.trig(zswitch)
|
||||
hvbouton=nil
|
||||
second_chance=nil
|
||||
zswitch=nil
|
||||
reset_reason=nil
|
||||
f= "boot.lua" if file.exists(f) then dofile(f) end
|
||||
f= "boot2.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
|
||||
f= "boot2.lua" if file.exists(f) then dofile(f) end
|
||||
elseif reset_reason == 6 then
|
||||
print("external reset")
|
||||
second_chance()
|
||||
else
|
||||
print("autre raison")
|
||||
second_chance()
|
||||
end
|
||||
|
||||
|
||||
398
WIFI_sniffer/cret_project/luatool.py
Executable file
398
WIFI_sniffer/cret_project/luatool.py
Executable file
@@ -0,0 +1,398 @@
|
||||
#!/usr/bin/env python2
|
||||
# -*- coding: utf-8 -*-
|
||||
version = "0.6.5 zf191021.1558"
|
||||
|
||||
print("luatool.py ver " + version)
|
||||
|
||||
#Améliorations
|
||||
# Pour voir les améliorations il faut 'chercher' les zzz
|
||||
|
||||
|
||||
#
|
||||
# ESP8266 luatool
|
||||
# Author e-mail: 4ref0nt@gmail.com
|
||||
# Site: http://esp8266.ru
|
||||
# Contributions from: https://github.com/sej7278
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it under
|
||||
# the terms of the GNU General Public License as published by the Free Software
|
||||
# Foundation; either version 2 of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
|
||||
# Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
import sys
|
||||
import serial
|
||||
from time import sleep
|
||||
import socket
|
||||
import argparse
|
||||
from os.path import basename
|
||||
|
||||
|
||||
tqdm_installed = True
|
||||
try:
|
||||
from tqdm import tqdm
|
||||
except ImportError, e:
|
||||
if e.message == 'No module named tqdm':
|
||||
tqdm_installed = False
|
||||
else:
|
||||
raise
|
||||
|
||||
|
||||
|
||||
class TransportError(Exception):
|
||||
"""Custom exception to represent errors with a transport
|
||||
"""
|
||||
def __init__(self, message):
|
||||
self.message = message
|
||||
|
||||
def __str__(self):
|
||||
return self.message
|
||||
|
||||
class AbstractTransport:
|
||||
def __init__(self):
|
||||
raise NotImplementedError('abstract transports cannot be instantiated.')
|
||||
|
||||
def close(self):
|
||||
raise NotImplementedError('Function not implemented')
|
||||
|
||||
def read(self, length):
|
||||
raise NotImplementedError('Function not implemented')
|
||||
|
||||
def writeln(self, data, check=1):
|
||||
raise NotImplementedError('Function not implemented')
|
||||
|
||||
def writer(self, data):
|
||||
self.writeln("file.writeline([==[" + data + "]==])\r")
|
||||
|
||||
def performcheck(self, expected):
|
||||
line = ''
|
||||
char = ''
|
||||
i = -1
|
||||
while char != chr(62): # '>'
|
||||
char = self.read(1)
|
||||
if char == '':
|
||||
raise Exception('No proper answer from MCU')
|
||||
if char == chr(13) or char == chr(10): # LF or CR
|
||||
if line != '':
|
||||
line = line.strip()
|
||||
# zzz191021 Affiche ce que l'on a reçu du NodeMCU
|
||||
if args.verbose:
|
||||
print("\n\nzread0957: {" + line + "\n}\n")
|
||||
|
||||
if line+'\r' == expected and not args.bar:
|
||||
sys.stdout.write(" -> ok")
|
||||
elif line+'\r' != expected:
|
||||
if line[:4] == "lua:":
|
||||
sys.stdout.write("\r\n\r\nLua ERROR: %s" % line)
|
||||
raise Exception('ERROR from Lua interpreter\r\n\r\n')
|
||||
else:
|
||||
expected = expected.split("\r")[0]
|
||||
sys.stdout.write("\r\n\r\nERROR")
|
||||
sys.stdout.write("\r\n send string : '%s'" % expected)
|
||||
sys.stdout.write("\r\n expected echo : '%s'" % expected)
|
||||
sys.stdout.write("\r\n but got answer : '%s'" % line)
|
||||
sys.stdout.write("\r\n\r\n")
|
||||
raise Exception('Error sending data to MCU\r\n\r\n')
|
||||
line = ''
|
||||
else:
|
||||
line += char
|
||||
if char == chr(62) and expected[i] == char:
|
||||
char = ''
|
||||
i += 1
|
||||
|
||||
|
||||
class SerialTransport(AbstractTransport):
|
||||
def __init__(self, port, baud, delay):
|
||||
self.port = port
|
||||
self.baud = baud
|
||||
self.serial = None
|
||||
self.delay = delay
|
||||
|
||||
try:
|
||||
self.serial = serial.Serial(port, baud)
|
||||
except serial.SerialException as e:
|
||||
raise TransportError(e.strerror)
|
||||
|
||||
self.serial.timeout = 3
|
||||
self.serial.interCharTimeout = 3
|
||||
|
||||
# zzz191021 juste après l'ouverture du port série, on attend le caractère '>'
|
||||
line = ''
|
||||
char = ''
|
||||
i = -1
|
||||
while char != chr(62): # '>'
|
||||
char = self.read(1)
|
||||
if char == '':
|
||||
raise Exception('No proper answer from MCU')
|
||||
line += char
|
||||
i += 1
|
||||
if args.verbose:
|
||||
print("line: ." + line + ".")
|
||||
|
||||
|
||||
def writeln(self, data, check=1):
|
||||
# zzz191020 on fait une petite pause avant l'envoi de chaque ligne
|
||||
sleep(self.delay)
|
||||
if self.serial.inWaiting() > 0:
|
||||
self.serial.flushInput()
|
||||
if len(data) > 0 and not args.bar:
|
||||
sys.stdout.write("\r\n->")
|
||||
sys.stdout.write(data.split("\r")[0])
|
||||
self.serial.write(data)
|
||||
# zzz191021 Affiche ce que l'on a envoyé au NodeMCU
|
||||
if args.verbose:
|
||||
print("\n\nzwrite0952: {" + data + "\n}\n")
|
||||
if check > 0:
|
||||
self.performcheck(data)
|
||||
elif not args.bar:
|
||||
sys.stdout.write(" -> send without check")
|
||||
|
||||
def read(self, length):
|
||||
return self.serial.read(length)
|
||||
|
||||
def close(self):
|
||||
self.serial.flush()
|
||||
self.serial.close()
|
||||
|
||||
|
||||
class TcpSocketTransport(AbstractTransport):
|
||||
def __init__(self, host, port):
|
||||
self.host = host
|
||||
self.port = port
|
||||
self.socket = None
|
||||
|
||||
try:
|
||||
self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
except socket.error as e:
|
||||
raise TransportError(e.strerror)
|
||||
|
||||
try:
|
||||
self.socket.connect((host, port))
|
||||
except socket.error as e:
|
||||
raise TransportError(e.strerror)
|
||||
# read intro from telnet server (see telnet_srv.lua)
|
||||
self.socket.recv(50)
|
||||
|
||||
def writeln(self, data, check=1):
|
||||
if len(data) > 0 and not args.bar:
|
||||
sys.stdout.write("\r\n->")
|
||||
sys.stdout.write(data.split("\r")[0])
|
||||
self.socket.sendall(data)
|
||||
if check > 0:
|
||||
self.performcheck(data)
|
||||
elif not args.bar:
|
||||
sys.stdout.write(" -> send without check")
|
||||
|
||||
def read(self, length):
|
||||
return self.socket.recv(length)
|
||||
|
||||
def close(self):
|
||||
self.socket.close()
|
||||
|
||||
|
||||
def decidetransport(cliargs):
|
||||
if cliargs.ip:
|
||||
data = cliargs.ip.split(':')
|
||||
host = data[0]
|
||||
if len(data) == 2:
|
||||
port = int(data[1])
|
||||
else:
|
||||
port = 23
|
||||
return TcpSocketTransport(host, port)
|
||||
else:
|
||||
return SerialTransport(cliargs.port, cliargs.baud, cliargs.delay)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
# parse arguments or use defaults
|
||||
parser = argparse.ArgumentParser(description='ESP8266 Lua script uploader.')
|
||||
parser.add_argument('--bar', action='store_true', help='Show a progress bar for uploads instead of printing each line')
|
||||
parser.add_argument('--delay', default=0.03, help='Delay in seconds between each write, default 0.03 sec.', type=float)
|
||||
parser.add_argument('--delete', default=None, help='Delete a lua/lc file from device.')
|
||||
parser.add_argument('--ip', default=None, help='Connect via telnet server (--ip IP[:port])')
|
||||
parser.add_argument('--zrestart', action='store_true', help='Restart the NodeMCU.')
|
||||
parser.add_argument('-a', '--append', action='store_true', help='Append source file to destination file.')
|
||||
parser.add_argument('-b', '--baud', default=115200, help='Baudrate, default 115200')
|
||||
parser.add_argument('-c', '--compile', action='store_true', help='Compile lua to lc after upload')
|
||||
parser.add_argument('-d', '--dofile', action='store_true', help='Run the Lua script after upload')
|
||||
parser.add_argument('-e', '--echo', action='store_true', help='Echo output of MCU until script is terminated.')
|
||||
parser.add_argument('-f', '--src', default='main.lua', help='Source file on computer, default main.lua')
|
||||
parser.add_argument('-i', '--id', action='store_true', help='Query the modules chip id.')
|
||||
parser.add_argument('-l', '--list', action='store_true', help='List files on device')
|
||||
parser.add_argument('-p', '--port', default='/dev/ttyUSB0', help='Device name, default /dev/ttyUSB0')
|
||||
parser.add_argument('-r', '--restart', action='store_true', help='Restart MCU after upload')
|
||||
parser.add_argument('-t', '--dest', default=None, help='Destination file on MCU, default to source file name')
|
||||
parser.add_argument('-v', '--verbose', action='store_true', help="Show progress messages.")
|
||||
parser.add_argument('-w', '--wipe', action='store_true', help='Delete all lua/lc files on device.')
|
||||
args = parser.parse_args()
|
||||
|
||||
transport = decidetransport(args)
|
||||
|
||||
if args.bar and not tqdm_installed:
|
||||
sys.stdout.write("You must install the tqdm library to use the bar feature\n")
|
||||
sys.stdout.write("To install, at the prompt type: \"pip install tqdm\"\n")
|
||||
sys.exit(0)
|
||||
|
||||
|
||||
if args.list:
|
||||
# zzz191020 Amélioré la sortie du listing des fichiers
|
||||
transport.writeln("print('\\n-----');local l = file.list();for k,v in pairs(l) do print(k..', size:'..v)end;print('-----\\n')\r", 0)
|
||||
while True:
|
||||
char = transport.read(1)
|
||||
if char == '' or char == chr(62): # '' or '>'
|
||||
break
|
||||
sys.stdout.write(char)
|
||||
sys.exit(0)
|
||||
|
||||
if args.id:
|
||||
transport.writeln("=node.chipid()\r", 0)
|
||||
id=""
|
||||
while True:
|
||||
char = transport.read(1)
|
||||
if char == '' or char == chr(62):
|
||||
break
|
||||
if char.isdigit():
|
||||
id += char
|
||||
print("\n"+id)
|
||||
sys.exit(0)
|
||||
|
||||
# zzz191020 Ajouté la fonction restart seule
|
||||
if args.zrestart:
|
||||
transport.writeln("node.restart()\r")
|
||||
sys.exit(0)
|
||||
|
||||
if args.wipe:
|
||||
transport.writeln("local l = file.list();for k,v in pairs(l) do print(k)end\r", 0)
|
||||
file_list = []
|
||||
fn = ""
|
||||
while True:
|
||||
char = transport.read(1)
|
||||
if char == '' or char == chr(62):
|
||||
break
|
||||
if char not in ['\r', '\n']:
|
||||
fn += char
|
||||
else:
|
||||
if fn:
|
||||
file_list.append(fn.strip())
|
||||
fn = ''
|
||||
for fn in file_list[1:]: # first line is the list command sent to device
|
||||
if args.verbose:
|
||||
sys.stderr.write("Delete file {} from device.\r\n".format(fn))
|
||||
transport.writeln("file.remove(\"" + fn + "\")\r")
|
||||
sys.exit(0)
|
||||
|
||||
if args.delete:
|
||||
transport.writeln("file.remove(\"" + args.delete + "\")\r")
|
||||
sys.exit(0)
|
||||
|
||||
if args.dest is None:
|
||||
args.dest = basename(args.src)
|
||||
# zzz191020 Affiche le fichier à envoyer
|
||||
print("File: " + args.src)
|
||||
|
||||
# open source file for reading
|
||||
try:
|
||||
try:
|
||||
f = open(args.src, "rt")
|
||||
except:
|
||||
import os
|
||||
base_dir = os.path.dirname(os.path.realpath(__file__))
|
||||
f = open(os.path.join(base_dir, args.src), "rt")
|
||||
os.chdir(base_dir)
|
||||
except:
|
||||
sys.stderr.write("Could not open input file \"%s\"\n" % args.src)
|
||||
sys.exit(1)
|
||||
|
||||
# Verify the selected file will not exceed the size of the serial buffer.
|
||||
# The size of the buffer is 256. This script does not accept files with
|
||||
# lines longer than 230 characters to have some room for command overhead.
|
||||
num_lines = 0
|
||||
for ln in f:
|
||||
if len(ln) > 230:
|
||||
sys.stderr.write("File \"%s\" contains a line with more than 240 "
|
||||
"characters. This exceeds the size of the serial buffer.\n"
|
||||
% args.src)
|
||||
f.close()
|
||||
sys.exit(1)
|
||||
num_lines += 1
|
||||
|
||||
# Go back to the beginning of the file after verifying it has the correct
|
||||
# line length
|
||||
f.seek(0)
|
||||
|
||||
# set serial timeout
|
||||
if args.verbose:
|
||||
sys.stderr.write("Upload starting\r\n")
|
||||
|
||||
# remove existing file on device
|
||||
if args.append==False:
|
||||
if args.verbose:
|
||||
sys.stderr.write("Stage 1. Deleting old file from flash memory")
|
||||
transport.writeln("file.open(\"" + args.dest + "\", \"w\")\r")
|
||||
transport.writeln("file.close()\r")
|
||||
transport.writeln("file.remove(\"" + args.dest + "\")\r")
|
||||
else:
|
||||
if args.verbose:
|
||||
sys.stderr.write("[SKIPPED] Stage 1. Deleting old file from flash memory [SKIPPED]")
|
||||
|
||||
|
||||
# read source file line by line and write to device
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nStage 2. Creating file in flash memory and write first line")
|
||||
if args.append:
|
||||
transport.writeln("file.open(\"" + args.dest + "\", \"a+\")\r")
|
||||
else:
|
||||
transport.writeln("file.open(\"" + args.dest + "\", \"w+\")\r")
|
||||
line = f.readline()
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nStage 3. Start writing data to flash memory...")
|
||||
if args.bar:
|
||||
for i in tqdm(range(0, num_lines)):
|
||||
transport.writer(line.strip())
|
||||
line = f.readline()
|
||||
else:
|
||||
while line != '':
|
||||
transport.writer(line.strip())
|
||||
line = f.readline()
|
||||
|
||||
# close both files
|
||||
f.close()
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nStage 4. Flush data and closing file")
|
||||
transport.writeln("file.flush()\r")
|
||||
transport.writeln("file.close()\r")
|
||||
|
||||
# compile?
|
||||
if args.compile:
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nStage 5. Compiling")
|
||||
transport.writeln("node.compile(\"" + args.dest + "\")\r")
|
||||
transport.writeln("file.remove(\"" + args.dest + "\")\r")
|
||||
|
||||
# restart or dofile
|
||||
if args.restart:
|
||||
transport.writeln("node.restart()\r")
|
||||
|
||||
if args.dofile: # never exec if restart=1
|
||||
transport.writeln("dofile(\"" + args.dest + "\")\r", 0)
|
||||
|
||||
if args.echo:
|
||||
if args.verbose:
|
||||
sys.stderr.write("\r\nEchoing MCU output, press Ctrl-C to exit")
|
||||
while True:
|
||||
sys.stdout.write(transport.read(1))
|
||||
|
||||
# close serial port
|
||||
transport.close()
|
||||
|
||||
# flush screen
|
||||
sys.stdout.flush()
|
||||
sys.stderr.flush()
|
||||
if not args.bar:
|
||||
sys.stderr.write("\r\n--->>> All done <<<---\r\n")
|
||||
29
WIFI_sniffer/cret_project/set_time.lua
Normal file
29
WIFI_sniffer/cret_project/set_time.lua
Normal file
@@ -0,0 +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 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_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()
|
||||
print(ztime_format(rtctime.get()))
|
||||
|
||||
93
WIFI_sniffer/cret_project/telnet_srv2.lua
Normal file
93
WIFI_sniffer/cret_project/telnet_srv2.lua
Normal file
@@ -0,0 +1,93 @@
|
||||
-- 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 zf191020.1932 \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
|
||||
|
||||
--zzz
|
||||
local function zconnection(s)
|
||||
print("Welcome to NodeMCU world.")
|
||||
end
|
||||
|
||||
socket:on("connection", zconnection)
|
||||
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")
|
||||
23
WIFI_sniffer/cret_project/test_toto.sh
Executable file
23
WIFI_sniffer/cret_project/test_toto.sh
Executable file
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
# Petit script pour tester tout le binz via le WIFI
|
||||
#zf191020.1954
|
||||
|
||||
# S'il y a des erreurs lors d'un téléchargement, il faut simplement augmenter un peu le délai !
|
||||
|
||||
IP="192.168.0.157"
|
||||
|
||||
chmod +x luatool.py
|
||||
|
||||
./luatool.py --ip $IP -l
|
||||
read -p "continue ?"
|
||||
./luatool.py --ip $IP --delete toto.lua
|
||||
read -p "continue ?"
|
||||
./luatool.py --ip $IP -l
|
||||
read -p "continue ?"
|
||||
./luatool.py --ip $IP -f toto.lua -d
|
||||
read -p "continue ?"
|
||||
./luatool.py --ip $IP -l
|
||||
read -p "continue ?"
|
||||
./luatool.py --ip $IP --delete toto.lua
|
||||
read -p "continue ?"
|
||||
./luatool.py --ip $IP -l
|
||||
3
WIFI_sniffer/cret_project/toto.lua
Normal file
3
WIFI_sniffer/cret_project/toto.lua
Normal file
@@ -0,0 +1,3 @@
|
||||
print("c'est toto !")
|
||||
|
||||
boottimer1:unregister()
|
||||
38
WIFI_sniffer/cret_project/upload.sh
Executable file
38
WIFI_sniffer/cret_project/upload.sh
Executable file
@@ -0,0 +1,38 @@
|
||||
#!/bin/bash
|
||||
# Petit script pour télécharger facilement tout le binz
|
||||
#zf191028.1459
|
||||
|
||||
# S'il y a des erreurs lors d'un téléchargement, il faut simplement augmenter un peu le délai !
|
||||
# Il est préférable de télécharger en premier les *gros* fichiers .lua !
|
||||
|
||||
# ATTENTION: cela efface tout le NodeMCU !
|
||||
|
||||
luatool_tty="/dev/cu.wchusbserial1410"
|
||||
|
||||
echo ""
|
||||
read -p "ATTENTION, cela va effacer tout le NodeMCU !"
|
||||
read -p "Etes-vous vraiment certain ?"
|
||||
|
||||
chmod +x luatool.py
|
||||
|
||||
./luatool.py --port $luatool_tty -w
|
||||
./luatool.py --port $luatool_tty -l
|
||||
read -p "Est-ce bien vide ?"
|
||||
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.06 -f telnet_srv2.lua
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.03 -f head.lua
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.03 -f flash_led_xfois.lua
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.001 -f wifi_info.lua
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.001 -f wifi_cli_start.lua
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.001 -f wifi_cli_conf.lua
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.001 -f wifi_ap_stop.lua
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.001 -f secrets_energy.lua
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.001 -f dir.lua
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.001 -f cat.lua
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.001 -f boot2.lua
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.001 -f boot.lua
|
||||
|
||||
./luatool.py --port $luatool_tty -l
|
||||
read -p "Pas eu d'erreur, on part à fond avec le init.lua ?"
|
||||
./luatool.py --port $luatool_tty --bar --delay 0.001 -f initz.lua -t init.lua
|
||||
echo -e "\nC'est tout bon ;-)"
|
||||
78
WIFI_sniffer/cret_project/web_srv2.lua
Normal file
78
WIFI_sniffer/cret_project/web_srv2.lua
Normal file
@@ -0,0 +1,78 @@
|
||||
-- petit script de serveur WEB avec Active Server Page ZYX
|
||||
|
||||
print("\n web_srv2.lua zf190728.1021 \n")
|
||||
|
||||
ztemp=12
|
||||
|
||||
-- envoie sur le port ouvert mais depuis l'environnement global !
|
||||
function zout(zstring)
|
||||
zzclient:send(zstring) -- envoie le résultat du code lua inline
|
||||
end
|
||||
|
||||
-- envoie un fichier HTML sur le port. ATTENTION: longueur de la ligne maximale de 1'024 bytes !
|
||||
function send_file(zclient, zfilename)
|
||||
print("start send html...")
|
||||
zclient:send("HTTP/1.1 200 OK\n")
|
||||
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
|
||||
file_web = file.open(zfilename, "r")
|
||||
if file_web then
|
||||
repeat
|
||||
local line = file_web:read('\n')
|
||||
if line then
|
||||
if string.find(line, "<%%") then
|
||||
-- print("start lua...")
|
||||
flag_lua_code = true -- bascule sur le code lua inline
|
||||
lua_code = ""
|
||||
elseif string.find(line, "%%>") then
|
||||
-- print("stop lua...")
|
||||
flag_lua_code = false -- revient sur le code HTML
|
||||
-- print("Et voici le code lua inline:\n"..lua_code)
|
||||
loadstring(lua_code)() --on exécute ici le code lua inline !
|
||||
elseif flag_lua_code then
|
||||
-- print(line)
|
||||
lua_code = lua_code..line -- récupère le code lua inline
|
||||
else
|
||||
zclient:send(line) -- envoie le code HTML
|
||||
end
|
||||
end
|
||||
until not line
|
||||
file_web:close() file_web = nil
|
||||
else
|
||||
zclient:send("<html><h1>"..zfilename.." not found - 404 error</h1><a href='/'>Home</a><br></html>")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
srv = net.createServer()
|
||||
srv:listen(80, function(conn)
|
||||
conn:on("receive", function(client, request)
|
||||
_, _, method, path, vars = string.find(request, "([A-Z]+) (.+)?(.+) HTTP")
|
||||
|
||||
print("zrequest: \n---\n"..request.."---")
|
||||
|
||||
-- print("method: ", method) print("path: ", path) print("vars: ", vars)
|
||||
|
||||
if not string.find(request, "/favicon.ico") then
|
||||
print("coucou")
|
||||
if (method == nil) then
|
||||
_, _, method, path = string.find(request, "([A-Z]+) (.+) HTTP")
|
||||
end
|
||||
print("method: ", method) print("path: ", path) print("vars: ", vars)
|
||||
_GET = {}
|
||||
if (vars ~= nil) then
|
||||
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
|
||||
_GET[k] = v
|
||||
print(k..": "..v)
|
||||
end
|
||||
end
|
||||
file_html=string.gsub(path, "/", "")
|
||||
-- print("file_html: ",file_html)
|
||||
send_file(client, file_html)
|
||||
end
|
||||
end)
|
||||
conn:on("sent", function(c) c:close() end)
|
||||
end)
|
||||
|
||||
|
||||
14
WIFI_sniffer/cret_project/wifi_ap_start.lua
Normal file
14
WIFI_sniffer/cret_project/wifi_ap_start.lua
Normal file
@@ -0,0 +1,14 @@
|
||||
-- Démarre le WIFI en mode AP
|
||||
|
||||
print("\n wifi_ap_start.lua zf191029.2123 \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
|
||||
10
WIFI_sniffer/cret_project/wifi_ap_stop.lua
Normal file
10
WIFI_sniffer/cret_project/wifi_ap_stop.lua
Normal file
@@ -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é")
|
||||
11
WIFI_sniffer/cret_project/wifi_cli_conf.lua
Normal file
11
WIFI_sniffer/cret_project/wifi_cli_conf.lua
Normal file
@@ -0,0 +1,11 @@
|
||||
-- Petit script pour configurer le client WIFI du NodeMCU
|
||||
|
||||
function wifi_cli_conf()
|
||||
print("\n wifi_cli_conf.lua zf190726.1912 \n")
|
||||
|
||||
-- les secrets sont maintenant initialisés par boot.lua !
|
||||
wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, save=true}
|
||||
end
|
||||
|
||||
wifi_cli_conf()
|
||||
wifi_cli_conf=nil
|
||||
20
WIFI_sniffer/cret_project/wifi_cli_start.lua
Normal file
20
WIFI_sniffer/cret_project/wifi_cli_start.lua
Normal file
@@ -0,0 +1,20 @@
|
||||
-- Petit script pour connecter le NodeMCU sur un AP Wifi avec l'accompte sauvé en EEPROM
|
||||
|
||||
function wifi_cli_start()
|
||||
print("\n wifi_cli_start.lua zf190310.1519 \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
|
||||
end
|
||||
|
||||
wifi_cli_start()
|
||||
wifi_cli_start=nil
|
||||
33
WIFI_sniffer/cret_project/wifi_info.lua
Normal file
33
WIFI_sniffer/cret_project/wifi_info.lua
Normal file
@@ -0,0 +1,33 @@
|
||||
-- Petit script pour afficher les infos actuel du WIFI
|
||||
print("\n wifi_info.lua zf190727.1220 \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())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current client config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid)
|
||||
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())
|
||||
local sta_config=wifi.sta.getconfig(true)
|
||||
print("Current client config:")
|
||||
print("\tssid:", sta_config.ssid)
|
||||
print("\tpassword:", sta_config.pwd)
|
||||
print("\tbssid:", sta_config.bssid)
|
||||
print("AP MAC: ", wifi.ap.getmac())
|
||||
print("AP IP: ", wifi.ap.getip())
|
||||
end
|
||||
19
WIFI_sniffer/cret_project/wifi_init.lua
Normal file
19
WIFI_sniffer/cret_project/wifi_init.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
-- Petit script pour initaliser une fois la couche WIFI
|
||||
|
||||
function wifi_init()
|
||||
print("\n wifi_init.lua zf191029.2133 \n")
|
||||
-- charge les secrets pour lw wifi
|
||||
f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
f= "wifi_ap_start.lua" if file.exists(f) then dofile(f) 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= "wifi_cli_stop.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
end
|
||||
|
||||
wifi_init()
|
||||
wifi_init=nil cli_ssid=nil cli_pwd=nil
|
||||
|
||||
|
||||
23
WIFI_sniffer/cret_project/z_index.html
Normal file
23
WIFI_sniffer/cret_project/z_index.html
Normal file
@@ -0,0 +1,23 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr" dir="ltr">
|
||||
|
||||
<head>
|
||||
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>ESP8266 home page</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>ESP8266 home page 190727.0941</h1>
|
||||
<h2>Différentes pages HTML:</h2>
|
||||
<h3>
|
||||
<a href="z_page1.html">Page 1, affichage de la température dynamique en code Lua inline.</a><br>
|
||||
<a href="z_page2.html">Page 2, tableau dynamique écrit en Lua inline.</a><br>
|
||||
<a href="z_page3.html">Page 3, affichage du capteur non linéaire corrigé.</a><br>
|
||||
<a href="z_page4.html?field1=11&field2=12&field3=13">Page 4, test de récupération d'arguments pour un web service.</a><br>
|
||||
<a href="api_hub_temp.html?field1=11&field2=12&field3=13">API HUB Temp, test d'un web service hub de mesures de température.</a><br>
|
||||
<a href="disp_temp.html">Affichage des températures, affiche les températures mesurées.</a><br>
|
||||
<a href="page_qui_existe_pag.html">Page qui n'existe pas !</a><br>
|
||||
</h3>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
26
WIFI_sniffer/cret_project/z_page1.html
Normal file
26
WIFI_sniffer/cret_project/z_page1.html
Normal file
@@ -0,0 +1,26 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr" dir="ltr">
|
||||
|
||||
<head>
|
||||
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>ESP8266 page 1</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>ESP8266 page 1 190127.1445</h1>
|
||||
<br>
|
||||
Coucou c'est la page 1 !<br>
|
||||
<a href="/">Retour à la home page...</a><br><br><br>
|
||||
|
||||
La température est:
|
||||
|
||||
<%
|
||||
ztemp=ztemp+1
|
||||
zout(ztemp.."°C")
|
||||
%>
|
||||
|
||||
<br>Mais il fait encore trop froid !<br>
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
51
WIFI_sniffer/cret_project/z_page2.html
Normal file
51
WIFI_sniffer/cret_project/z_page2.html
Normal file
@@ -0,0 +1,51 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr" dir="ltr">
|
||||
|
||||
<head>
|
||||
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>ESP8266 page 2</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>ESP8266 page 2 190127.1449</h1>
|
||||
<br>
|
||||
Coucou c'est la page 2 !<br>
|
||||
<a href="/">Retour à la home page...</a><br><br><br>
|
||||
|
||||
Voici un tableau dynamique écrit en Lua inline.<br><br>
|
||||
|
||||
Le code Lua pour créer ce tableau se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
|
||||
Les données du tableau viennent du NodeMCU !<br><br>
|
||||
|
||||
<%
|
||||
-- création du tableau sur le NodeMCUjuste juste pour la démo ici !
|
||||
zmac_adrs={}
|
||||
zmac_adrs["b8:d7:af:a6:bd:86"]={["zname"]="S7 zf", ["zrssi"]=45, ["ztime"]="12:03:36"}
|
||||
zmac_adrs["cc:c0:79:7d:f5:d5"]={["zname"]="S7 Mélanie", ["zrssi"]=50, ["ztime"]="14:23:46"}
|
||||
zmac_adrs["5c:f9:38:a1:f7:f0"]={["zname"]="MAC zf", ["zrssi"]=40, ["ztime"]="11:53:16"}
|
||||
zmac_adrs["d8:30:62:5a:d6:3a"]={["zname"]="IMAC Maman", ["zrssi"]=55, ["ztime"]="17:07:23"}
|
||||
%>
|
||||
|
||||
<table border='1'>
|
||||
<tr>
|
||||
<th>MAC</th><th>Name</th><th>RSSI</th><th>Time</th>
|
||||
</tr>
|
||||
<%
|
||||
for k, v in pairs(zmac_adrs) do
|
||||
zout("<tr>\n")
|
||||
zout("\t<td>" .. k .. "</td>\n")
|
||||
zout("\t<td>" .. tostring(zmac_adrs[k]["zname"]) .. "</td>\n")
|
||||
zout("\t<td>" .. tostring(zmac_adrs[k]["zrssi"]) .. "</td>\n")
|
||||
zout("\t<td>" .. tostring(zmac_adrs[k]["ztime"]) .. "</td>\n")
|
||||
zout("</tr>\n")
|
||||
end
|
||||
%>
|
||||
</table>
|
||||
|
||||
<%
|
||||
-- libère la mémoire du tableau sur le NodeMCU qui avait été créé pour la démo ici !
|
||||
zmac_adrs=nil
|
||||
%>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
50
WIFI_sniffer/cret_project/z_page3.html
Normal file
50
WIFI_sniffer/cret_project/z_page3.html
Normal file
@@ -0,0 +1,50 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr" dir="ltr">
|
||||
|
||||
<head>
|
||||
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>ESP8266 page 3</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>ESP8266 page 3 190505.1156</h1>
|
||||
<br>
|
||||
Coucou c'est la page 3 !<br>
|
||||
<a href="/">Retour à la home page...</a><br><br><br>
|
||||
|
||||
Voici le résultat du capteur non linéaire corrigé avec une table
|
||||
d'interpolation dans un fichier .csv sur la flash.<br><br>
|
||||
|
||||
Le code Lua pour afficher ce résultat se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
|
||||
Les données viennent du NodeMCU !<br><br>
|
||||
|
||||
<%
|
||||
zout("Il reste: "..node.heap().." de RAM !<br><br>\n")
|
||||
%>
|
||||
|
||||
<%
|
||||
zx0=83
|
||||
get_correction(zx0)
|
||||
zout("la valeur corrigée de "..zx0.." est "..zy0.."<br>")
|
||||
%>
|
||||
|
||||
<%
|
||||
zx0=91
|
||||
get_correction(zx0)
|
||||
zout("la valeur corrigée de "..zx0.." est "..zy0.."<br>")
|
||||
%>
|
||||
|
||||
<%
|
||||
zx0=100
|
||||
get_correction(zx0)
|
||||
zout("la valeur corrigée de "..zx0.." est "..zy0.."<br>")
|
||||
%>
|
||||
|
||||
<br>Yeah... cela fonctionne vachement bien !<br><br>
|
||||
|
||||
<%
|
||||
zout("Il reste: "..node.heap().." de RAM !<br><br>\n")
|
||||
%>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
53
WIFI_sniffer/cret_project/z_page4.html
Normal file
53
WIFI_sniffer/cret_project/z_page4.html
Normal file
@@ -0,0 +1,53 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr" dir="ltr">
|
||||
|
||||
<head>
|
||||
<meta charset='utf-8' name='viewport' content='width=device-width, initial-scale=1.0'>
|
||||
<title>ESP8266 page 3</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<h1>ESP8266 page 4 190726.1955</h1>
|
||||
<br>
|
||||
Web service concentrateur de mesures de température !<br>
|
||||
<a href="/">Retour à la home page...</a><br><br><br>
|
||||
|
||||
Test d'un web service qui fonctionne avec l'Active Server Page ZYX.<br><br>
|
||||
|
||||
Le code Lua pour afficher ce résultat se trouve dans le code HTML de cette page et est exécuté sur le NodeMCU.<br>
|
||||
Les données viennent du NodeMCU !<br><br>
|
||||
|
||||
<%
|
||||
zout("Il reste: "..node.heap().." de RAM !<br><br>\n")
|
||||
%>
|
||||
|
||||
Les arguments du web service (GET) sont:<br><br>
|
||||
<%
|
||||
if (vars ~= nil) then
|
||||
zout("<br>vars: "..vars.."<br>")
|
||||
for k, v in string.gmatch(vars, "(%w+)=(%w+)&*") do
|
||||
_GET[k] = v
|
||||
zout(k..": "..v.."<br>")
|
||||
if k == "field1" then
|
||||
ztemp1_conc = v
|
||||
elseif k == "field2" then
|
||||
ztemp2_conc = v
|
||||
elseif k == "field3" then
|
||||
ztemp3_conc = v
|
||||
end
|
||||
end
|
||||
end
|
||||
zout("<br>Les températures récupérées sont: "..ztemp1_conc..", "..ztemp2_conc..", "..ztemp3_conc)
|
||||
%>
|
||||
|
||||
|
||||
|
||||
|
||||
<br><br>Yeah... cela fonctionne vachement bien !<br><br>
|
||||
|
||||
<%
|
||||
zout("Il reste: "..node.heap().." de RAM !<br><br>\n")
|
||||
%>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user