Re-complètement encore une fois refactorisé la procédure de boot, j'ai gagné 10kB de RAM, soit 25% :-)
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
# 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
|
||||
cd '/Users/zuzu/Desktop/NodeMCU/NodeMCU_Lua/WIFI_sniffer/msl_project'
|
||||
export luatool_tty="/dev/cu.wchusbserial1410"
|
||||
export zIP="192.168.0.137"
|
||||
export zport="23"
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
-- Scripts à charger après le boot pour démarrer le core system
|
||||
|
||||
print("\n boot.lua zf191030.1930 \n")
|
||||
print("\n boot.lua zf191030.2012 \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= "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
|
||||
function boot()
|
||||
--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= "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
|
||||
end
|
||||
boot()
|
||||
|
||||
|
||||
@@ -1,53 +1,43 @@
|
||||
-- Scripts à charger après le boot pour démarrer son projet
|
||||
|
||||
print("\n boot2.lua zf191030.1958 \n")
|
||||
print("\n boot2.lua zf191030.2038 \n")
|
||||
|
||||
function boot2()
|
||||
|
||||
second_chance=nil
|
||||
|
||||
second_chance=nil initz=nil boot=nil
|
||||
f= "flash_led_xfois.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
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()
|
||||
|
||||
boot2_tmr=tmr.create()
|
||||
boot2_tmr:alarm(1*1000, tmr.ALARM_AUTO , function()
|
||||
if wifi.sta.getip() == nil then
|
||||
print("Connecting to AP...")
|
||||
xfois =2 blink_LED ()
|
||||
else
|
||||
wifitimer1:unregister()
|
||||
boot2_tmr: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
|
||||
|
||||
|
||||
|
||||
boot2_tmr=nil secrets_wifi=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= "b.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
f=nil
|
||||
|
||||
tmr.create():alarm(3*1000, tmr.ALARM_SINGLE, function()
|
||||
print("BOOOOUM, y'a plus de boot2 !")
|
||||
wifi_info=nil boot2=nil
|
||||
end)
|
||||
|
||||
end
|
||||
end)
|
||||
|
||||
tmr.create():alarm(3*1000, tmr.ALARM_SINGLE, function()
|
||||
boot2=nil
|
||||
end)
|
||||
|
||||
end
|
||||
|
||||
boot2()
|
||||
@@ -59,12 +49,6 @@ tmr.create():alarm(1*1000, tmr.ALARM_AUTO, function()
|
||||
end)
|
||||
]]
|
||||
|
||||
|
||||
heartbeat=nil
|
||||
--heartbeat()
|
||||
|
||||
|
||||
--[[
|
||||
for k,v in pairs(_G) do print(k,v) end
|
||||
]]
|
||||
|
||||
|
||||
@@ -3,61 +3,63 @@
|
||||
-- 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")
|
||||
print("\n init.lua zf191030.2015 \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()
|
||||
function initz()
|
||||
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
|
||||
end)
|
||||
initalarme2=tmr.create()
|
||||
initalarme2:alarm(30*1000, tmr.ALARM_SINGLE, function()
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
initz()
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- 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")
|
||||
print("\n set_time.lua zf191030.2026 \n")
|
||||
|
||||
--source: https://www.freeformatter.com/epoch-timestamp-to-date-converter.html
|
||||
|
||||
@@ -20,13 +20,13 @@ function ztime_uncompress(ztime_short)
|
||||
end
|
||||
|
||||
function ztime_format(ztime)
|
||||
tm = rtctime.epoch2cal(ztime + 3600)
|
||||
local 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()
|
||||
tmr.create():alarm(2*1000, tmr.ALARM_SINGLE, function()
|
||||
print(ztime_format(rtctime.get()))
|
||||
end)
|
||||
|
||||
|
||||
@@ -1,40 +1,44 @@
|
||||
-- Petit script pour afficher les infos actuel du WIFI
|
||||
print("\n wifi_info.lua zf191030.1911 \n")
|
||||
print("\n wifi_info.lua zf191030.2017 \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\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\n")
|
||||
print("CLIENT 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.."\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())
|
||||
function wifi_info()
|
||||
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\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\n")
|
||||
print("CLIENT 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.."\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
|
||||
end
|
||||
wifi_info()
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
-- Petit script pour initaliser une fois la couche WIFI
|
||||
-- Petit script pour initaliser la couche WIFI
|
||||
|
||||
function wifi_init()
|
||||
print("\n wifi_init.lua zf191030.1914 \n")
|
||||
print("\n wifi_init.lua zf191030.2040 \n")
|
||||
-- charge les secrets pour le wifi
|
||||
f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
|
||||
|
||||
@@ -16,10 +16,3 @@ end
|
||||
|
||||
wifi_init()
|
||||
|
||||
--[[
|
||||
wifi.setmode(wifi.STATIONAP,save)
|
||||
print(wifi.getdefaultmode())
|
||||
print(wifi.getmode())
|
||||
|
||||
|
||||
]]
|
||||
|
||||
Reference in New Issue
Block a user