Complètement en train de remanier la procédure de boot. Ne fonctionne pas encore !

This commit is contained in:
Christian Zufferey
2019-10-30 19:58:42 +01:00
parent 9adbbabaed
commit 03a82341f0
31 changed files with 808 additions and 115 deletions

View File

@@ -112,6 +112,7 @@ ssh -t -L 2323:localhost:2323 ubuntu@www.zuzutest.ml ssh -N -L 2323:192.168.1.11
Pour le Crêt
ssh -N -L 2323:192.168.0.137:23 admin@z.zufferey.com -p 1822
ssh -N -L 2323:192.168.0.122:23 admin@z.zufferey.com -p 1822
ATTENTION: dans un deuxième terminal !
export zIP="localhost"

View 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

View File

@@ -1,5 +1,5 @@
# Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom
# zf191028.1918
# zf191030.0851
# si luatool ne marche pas sur le MAC, il faut lire ceci:
# https://docs.google.com/document/d/1q64uK3IMOgEDdKaIAttbYuFt4GuLQ06k3FLeyfCsWLg/edit#heading=h.bmefcu67uwj0
@@ -10,31 +10,81 @@
# ALT+CMD+F bascule entre le terminal et l'éditeur
# définitions à faire AVANT !
cd /Users/zuzu/Desktop/NodeMCU/NodeMCU_Lua/WIFI_sniffer/cret_project
export luatool_tty="/dev/cu.wchusbserial1410"
export zIP="192.168.43.230"
export zIP="192.168.0.137"
export zport="23"
cd '/Users/zuzu/Google Drive/FamilleZ Share/FamilleZ/Papa/LUA/NodeMCU ESP8266/NodeMCU_Lua/WIFI_sniffer/cret_project'
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
# ouvrir et fermer (ALT+N+.) une session telnet sur le NodeMCU avec l'adresse zIP)
telnet -rN $zIP $zport
~.
node.restart()
collectgarbage()
=node.heap()
# commandes lua pour ce projet
verbose=true
verbose=false
zsort_rssi() zshow()
#commandes luatool pour ce projet
./luatool.py --ip $zIP -f 0_get_data.lua
./luatool.py --ip $zIP -f 0_send_data.lua
./luatool.py --ip $zIP -f cat.lua
./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
t=12
t=nil
print(pcall(function () print("2"..t) end))
# ici c'est maintenant ;-)
~.
./luatool.py --ip $zIP:$zport -f b.lua
./luatool.py --ip $zIP:$zport --zrestart
telnet -rN $zIP $zport
zsort_rssi() zshow()
print(ztrig_rssi)
ztrig_rssi=-1000
ztrig_rssi=-90
# test de la gestion des erreurs
~.
./luatool.py --ip $zIP:$zport -f c.lua
#./luatool.py --ip $zIP:$zport --zrestart
telnet -rN $zIP $zport
status, err = pcall(function () dofile("c.lua") end) if status==false then print("Error: ",err) end
zerr=nil
zerr=1
ztmr_tst_err:unregister()
~.
./luatool.py --ip $zIP -f head.lua
telnet -rN $zIP
./luatool.py --ip $zIP:$zport -f head.lua
telnet -rN $zIP $zport
dofile("head.lua")
zhead("telnet_srv2.lua")
@@ -49,16 +99,20 @@ cat("boot2.lua")
# commandes luatool
./luatool.py -h
./luatool.py --ip $zIP -i
./luatool.py --ip $zIP -l
./luatool.py --ip $zIP -f toto.lua -d
./luatool.py --ip $zIP --delete toto.lua
./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"

View File

@@ -0,0 +1,140 @@
-- 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 zf191030.1407 \n")
ztrig_rssi=-90
--f= "set_time.lua" if file.exists(f) then dofile(f) end
-- apzuzu6 38:2c:4a:4e:d3:d8
--zadrs, zname, zrssi, ztime0, ztime1
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"
function zshow()
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
function zround(num, dec)
local mult = 10^(dec or 0)
return math.floor(num * mult + 0.5) / mult
end
function zsniff(T)
print("toto1950: "..T.RSSI)
if T.RSSI > ztrig_rssi then
print("\n\tMAC: ".. T.MAC.."\n\tRSSI: "..T.RSSI)
-- n'existe plus zf191030.1406 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()
]]

View File

@@ -1,15 +1,11 @@
-- Scripts à charger après le boot pour démarrer le core system
print("\n boot.lua zf191020.1928 \n")
print("\n boot.lua zf191030.1930 \n")
-- charge ses propres secrets
f= "secrets_energy.lua" if file.exists(f) then dofile(f) end
--f= "led_rgb.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= "telnet_srv2.lua" if file.exists(f) then dofile(f) end
f= "wifi_init.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

View File

@@ -1,22 +1,70 @@
-- Scripts à charger après le boot pour démarrer son appli
-- Scripts à charger après le boot pour démarrer son projet
print("\n boot2.lua zf191028.1900 \n")
print("\n boot2.lua zf191030.1958 \n")
second_chance=nil
function heartbeat()
function boot2()
second_chance=nil
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
flash_led_xfois()
boottimer1=tmr.create()
boottimer1:alarm(1*1000, tmr.ALARM_AUTO, function()
xfois =2
blink_LED ()
if false then
tmr.create():alarm(1*1000, tmr.ALARM_AUTO, function()
xfois =2
blink_LED ()
end)
end
wifitimer1=tmr.create()
wifitimer1:alarm(1*1000, tmr.ALARM_AUTO , function()
if wifi.sta.getip() == nil then
print("Connecting to AP...")
xfois =2 blink_LED ()
else
wifitimer1:unregister()
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
wifi_init=nil
cli_ssid=nil
cli_pwd=nil
ap_ssid=nil
ap_pwd=nil
f= "wifi_info.lua" if file.exists(f) then dofile(f) end
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
f= "set_time.lua" if file.exists(f) then dofile(f) end
collectgarbage()
-- f= "b.lua" if file.exists(f) then dofile(f) end
f=nil
end
end)
tmr.create():alarm(3*1000, tmr.ALARM_SINGLE, function()
boot2=nil
end)
end
--f= "0_get_data.lua" if file.exists(f) then dofile(f) end
--f= "0_send_data.lua" if file.exists(f) then dofile(f) end
--f= "0_cron.lua" if file.exists(f) then dofile(f) end
boot2()
--[[
tmr.create():alarm(1*1000, tmr.ALARM_AUTO, function()
print(node.heap())
end)
]]
f=nil
heartbeat=nil
--heartbeat()
--[[
for k,v in pairs(_G) do print(k,v) end
]]

View File

@@ -0,0 +1,37 @@
-- Scripts pour tester l'affichage des erreurs quand on se trouve ne remote telnet
-- source: https://www.lua.org/pil/8.4.html
-- source: https://riptutorial.com/lua/example/16000/using-pcall
--[[
Usage:
après l'avoir lancé on peut faire varier le contenu de la variable zerr pour cérer des erreurs répétitives
Commandes à envoyer via un terminal:
~.
./luatool.py --ip $zIP:$zport -f c.lua
#./luatool.py --ip $zIP:$zport --zrestart
telnet -rN $zIP $zport
status, err = pcall(function () dofile("c.lua") end) if status==false then print("Error: ",err) end
zerr=nil
zerr=1
ztmr_tst_err:unregister()
]]
print("\n c.lua zf191030.1231 \n")
zerr=1
ztmr_tst_err = tmr.create()
-- le code à tester DOIT être encapsulé dans une fonction
function zfoo()
print("toto: "..zerr)
end
-- timer pour générer des erreurs répétitives
ztmr_tst_err:alarm(3*1000, tmr.ALARM_AUTO, function()
-- test du code
local status, err = pcall(function () zfoo() end) if status==false then print("Error: ",err) end
end)
--

View File

@@ -1,7 +1,7 @@
-- programme pour faire clignoter x fois une LED avec un rapport on/off
function flash_led_xfois()
print("\n flash_led_xfois.lua zf190601.1618 \n")
print("\n flash_led_xfois.lua zf191029.2111 \n")
--zLED=0 --NodeMCU
zLED=4 --EPS-M3
@@ -30,10 +30,11 @@ function flash_led_xfois()
end
end
-- xfois =2
-- blink_LED ()
end
flash_led_xfois()
--[[
xfois =2
blink_LED ()
]]

View File

@@ -0,0 +1,73 @@
# Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom
# zf191028.1918
# 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="192.168.43.230"
# ouvrir et fermer (ALT+n+.) une session telnet sur le NodeMCU avec l'adresse zIP)
telnet -rN $zIP
~.
node.restart()
=node.heap()
# commandes lua pour ce projet
verbose=true
verbose=false
#commandes luatool pour ce projet
./luatool.py --ip $zIP -f 0_get_data.lua
./luatool.py --ip $zIP -f 0_send_data.lua
./luatool.py --ip $zIP -f cat.lua
~.
./luatool.py --ip $zIP -f head.lua
telnet -rN $zIP
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 -i
./luatool.py --ip $zIP -l
./luatool.py --ip $zIP -f toto.lua -d
./luatool.py --ip $zIP --delete toto.lua
# création des tunnels ssh
ATTENTION: dans un premier terminal !
ssh -t -L 2323:localhost:2323 ubuntu@www.zuzutest.ml ssh -N -L 2323:192.168.1.111:23 ubuntu@localhost -p 20221
ATTENTION: dans un deuxième terminal !
export zIP="localhost"
export zport="2323"
telnet -rN $zIP $zport
~.
node.restart()
=node.heap()
.

View File

@@ -0,0 +1,36 @@
-- 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 zf191030.1943 \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()
tmr.create():alarm(3*1000, tmr.ALARM_SINGLE, function()
print(ztime_format(rtctime.get()))
end)

View File

@@ -1,23 +0,0 @@
#!/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

View File

@@ -1,3 +0,0 @@
print("c'est toto !")
boottimer1:unregister()

View File

@@ -0,0 +1,42 @@
#!/bin/bash
# Petit script pour télécharger facilement tout le binz via le port série
#zf191030.1832
# 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.06 -f b.lua
./luatool.py --port $luatool_tty --bar --delay 0.03 -f web_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_init.lua
./luatool.py --port $luatool_tty --bar --delay 0.001 -f wifi_info.lua
./luatool.py --port $luatool_tty --bar --delay 0.001 -f set_time.lua
./luatool.py --port $luatool_tty --bar --delay 0.001 -f secrets_wifi.lua
./luatool.py --port $luatool_tty --bar --delay 0.001 -f secrets_project.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 c.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
./luatool.py --port $luatool_tty -l
echo -e "\nC'est tout bon ;-)"

View 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)

View File

@@ -1,10 +0,0 @@
-- 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é")

View File

@@ -1,11 +0,0 @@
-- 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

View File

@@ -1,20 +0,0 @@
-- 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

View File

@@ -1,5 +1,5 @@
-- Petit script pour afficher les infos actuel du WIFI
print("\n wifi_info.lua zf190727.1220 \n")
print("\n wifi_info.lua zf191030.1911 \n")
local zmodewifi=wifi.getmode()
@@ -16,18 +16,25 @@ elseif zmodewifi == wifi.STATION then
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())
print("WIFI mode AP\n")
print("AP IP: ", wifi.ap.getip())
print("Current AP config:")
local ap_config=wifi.ap.getconfig(true)
print("\tssid:", ap_config.ssid)
print("\tpassword:", ap_config.pwd)
print("\tbssid:", wifi.ap.getmac())
elseif zmodewifi == wifi.STATIONAP then
print("WIFI mode CLI+AP")
print("Connected IP:\n",wifi.sta.getip())
print("WIFI mode CLI+AP\n")
print("CLIENT IP:\n",wifi.sta.getip())
local sta_config=wifi.sta.getconfig(true)
print("Current client config:")
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("\tbssid:", sta_config.bssid.."\n")
print("AP IP: ", wifi.ap.getip())
print("Current AP config:")
local ap_config=wifi.ap.getconfig(true)
print("\tssid:", ap_config.ssid)
print("\tpassword:", ap_config.pwd)
print("\tbssid:", wifi.ap.getmac())
end

View File

@@ -0,0 +1,25 @@
-- Petit script pour initaliser une fois la couche WIFI
function wifi_init()
print("\n wifi_init.lua zf191030.1914 \n")
-- charge les secrets pour le wifi
f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
wifi.setmode(wifi.STATIONAP,true)
wifi.ap.config({ ssid = ap_ssid.." "..wifi.ap.getmac(), pwd = ap_pwd, save=true })
wifi.sta.config{ssid=cli_ssid, pwd=cli_pwd, auto=true, save=true}
wifi.sta.autoconnect(1)
wifi.sta.connect()
end
wifi_init()
--[[
wifi.setmode(wifi.STATIONAP,save)
print(wifi.getdefaultmode())
print(wifi.getmode())
]]

View 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>

View 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>

View 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>

View 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>

View 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>