Complètement refactorisé la procédure de boot (initz.lua)

Maintenant les *secrets* sont chargés au moment de l'init.lua et
l'aiguillage du boot *dsleep* se fait en fonction de la variable
node_mode. Ainsi c'est le même iniz.lua et wifi_init.lua pour les
différents projets NodeMCU.
Reste encore à faire de pouvoir sauver deux possibilités de connexions
WIFI dans les secrets_wifi afin de pouvoir se connecter sur le
WIFI du smartphone en cas de dépannage sur le terrain
This commit is contained in:
Christian Zufferey
2020-08-16 14:58:54 +02:00
parent cca4683200
commit a9abd91aa5
5 changed files with 54 additions and 34 deletions

View File

@@ -1,6 +1,6 @@
-- Scripts pour tester l'écoute des AP WIFI
print("\n wifi_scan.lua zf200815.1454 \n")
print("\n wifi_scan.lua zf200816.1417 \n")
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
@@ -12,7 +12,7 @@ function save_flash(zstr_ap_wifi)
ztime1 = tostring(rtctime.get() + 2*3600 - ztime2020)
local zstr = ztime1..", "..zstr_ap_wifi
if verbose then print("saving to flash: "..zstr) end
file.open(z_logs_ap_wifi, "a+") file.writeline(zstr) file.close()
file.open(logs_ap_wifi, "a+") file.writeline(zstr) file.close()
end
-- print AP list in new format

View File

@@ -1,9 +1,11 @@
# Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom
# zf200815.1253
# zf200816.1420
Todo à faire pour ce projet !
- éviter de trop remplir la FLASH !
J'ai encore 3x problèmes à régler !

View File

@@ -1,5 +1,5 @@
-- fonction cat() pour afficher le contenu d'un fichier dans la flash
print("\n cat2.lua zf200725.1319 \n")
print("\n cat2.lua zf200816.1417 \n")
print("\nusage:")
print(" cat2(\"filename\")")
@@ -17,7 +17,7 @@ function zprintline()
end
function cat2()
zfilei = file.open(z_logs_ap_wifi, "r")
zfilei = file.open(logs_ap_wifi, "r")
zline = file.readline()
ztmr_cat1:alarm(50, tmr.ALARM_AUTO, zprintline)
end

View File

@@ -3,7 +3,7 @@
-- 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 zf200725.1150 \n")
print("\n init.lua zf200816.1421 \n")
verbose = true
@@ -52,22 +52,40 @@ function initz()
print("reset_reason: ",reset_reason)
if reset_reason == 0 then
print("power on")
second_chance()
if node_mode == "dsleep" then
print("dsleep wake up")
f = "0_dsleep2.lua" if file.exists(f) then dofile(f) end
else
second_chance()
end
elseif reset_reason == 4 then
print("node.restart")
initz_end()
elseif reset_reason == 5 then
print("dsleep wake up")
initz_end()
if node_mode == "dsleep" then
print("dsleep wake up")
f = "0_dsleep2.lua" if file.exists(f) then dofile(f) end
else
initz_end()
end
elseif reset_reason == 6 then
print("external reset")
print("dsleep wake up")
f = "0_dsleep2.lua" if file.exists(f) then dofile(f) end
if node_mode == "dsleep" then
print("dsleep wake up")
f = "0_dsleep2.lua" if file.exists(f) then dofile(f) end
else
initz_end()
end
else
print("autre raison")
second_chance()
end
end
f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
initz()
--[[

View File

@@ -1,10 +1,10 @@
-- Petit script pour initaliser la couche WIFI
function wifi_init()
print("\n wifi_init.lua zf200814.1917 \n")
print("\n wifi_init.lua zf200816.1435 \n")
f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
f= "secrets_project.lua" if file.exists(f) then dofile(f) end
-- f= "secrets_wifi.lua" if file.exists(f) then dofile(f) end
-- f= "secrets_project.lua" if file.exists(f) then dofile(f) end
function wifi_init_end()
tmr_wifi_init1:unregister() i=nil
@@ -29,28 +29,28 @@ function wifi_init()
end
if file.exists("_setup_wifi_") then
print("dsleep wake up")
file.remove("_setup_wifi_")
f = "0_dsleep2.lua" if file.exists(f) then dofile(f) end
--
-- print("setup wifi...")
-- print("dsleep wake up")
-- file.remove("_setup_wifi_")
-- wifi.sta.config{ssid="", pwd=""} wifi.sta.connect()
-- if zLED == nil then zLED = 4 end
-- gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
-- tmr_wifi_init4=tmr.create()
-- tmr_wifi_init4:alarm(0.1*1000, tmr.ALARM_AUTO , function()
-- gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
-- end)
-- tmr.create():alarm(90*1000, tmr.ALARM_SINGLE, function()
-- node.restart()
-- end)
-- enduser_setup.start(function()
-- print("on est sortit du setup wifi et on restart !")
-- node.restart()
-- end)
-- print("setup gadget lancé...")
-- f = "0_dsleep2.lua" if file.exists(f) then dofile(f) end
print("setup wifi...")
file.remove("_setup_wifi_")
wifi.sta.config{ssid="", pwd=""} wifi.sta.connect()
if zLED == nil then zLED = 4 end
gpio.write(zLED, gpio.HIGH) gpio.mode(zLED, gpio.OUTPUT)
tmr_wifi_init4=tmr.create()
tmr_wifi_init4:alarm(0.1*1000, tmr.ALARM_AUTO , function()
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
end)
tmr.create():alarm(90*1000, tmr.ALARM_SINGLE, function()
node.restart()
end)
enduser_setup.start(function()
print("on est sortit du setup wifi et on restart !")
node.restart()
end)
print("setup gadget lancé...")
else