From a9abd91aa500df1b78cf30282cad27c916d8be73 Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Sun, 16 Aug 2020 14:58:54 +0200 Subject: [PATCH] =?UTF-8?q?Compl=C3=A8tement=20refactoris=C3=A9=20la=20pro?= =?UTF-8?q?c=C3=A9dure=20de=20boot=20(initz.lua)=20Maintenant=20les=20*sec?= =?UTF-8?q?rets*=20sont=20charg=C3=A9s=20au=20moment=20de=20l'init.lua=20e?= =?UTF-8?q?t=20l'aiguillage=20du=20boot=20*dsleep*=20se=20fait=20en=20fonc?= =?UTF-8?q?tion=20de=20la=20variable=20node=5Fmode.=20Ainsi=20c'est=20le?= =?UTF-8?q?=20m=C3=AAme=20iniz.lua=20et=20wifi=5Finit.lua=20pour=20les=20d?= =?UTF-8?q?iff=C3=A9rents=20projets=20NodeMCU.=20Reste=20encore=20=C3=A0?= =?UTF-8?q?=20faire=20de=20pouvoir=20sauver=20deux=20possibilit=C3=A9s=20d?= =?UTF-8?q?e=20connexions=20WIFI=20dans=20les=20secrets=5Fwifi=20afin=20de?= =?UTF-8?q?=20pouvoir=20se=20connecter=20sur=20le=20WIFI=20du=20smartphone?= =?UTF-8?q?=20en=20cas=20de=20d=C3=A9pannage=20sur=20le=20terrain?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DeepSleep/Pet_tracker_3/0_wifi_scan.lua | 4 +- DeepSleep/Pet_tracker_3/_zremote_cmd.txt | 4 +- DeepSleep/Pet_tracker_3/cat2.lua | 4 +- DeepSleep/Pet_tracker_3/initz.lua | 28 +++++++++++--- DeepSleep/Pet_tracker_3/wifi_init.lua | 48 ++++++++++++------------ 5 files changed, 54 insertions(+), 34 deletions(-) diff --git a/DeepSleep/Pet_tracker_3/0_wifi_scan.lua b/DeepSleep/Pet_tracker_3/0_wifi_scan.lua index 8702a92..efdccc7 100644 --- a/DeepSleep/Pet_tracker_3/0_wifi_scan.lua +++ b/DeepSleep/Pet_tracker_3/0_wifi_scan.lua @@ -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 diff --git a/DeepSleep/Pet_tracker_3/_zremote_cmd.txt b/DeepSleep/Pet_tracker_3/_zremote_cmd.txt index 57663e3..4d09612 100644 --- a/DeepSleep/Pet_tracker_3/_zremote_cmd.txt +++ b/DeepSleep/Pet_tracker_3/_zremote_cmd.txt @@ -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 ! diff --git a/DeepSleep/Pet_tracker_3/cat2.lua b/DeepSleep/Pet_tracker_3/cat2.lua index e65efaa..9ed78f4 100644 --- a/DeepSleep/Pet_tracker_3/cat2.lua +++ b/DeepSleep/Pet_tracker_3/cat2.lua @@ -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 diff --git a/DeepSleep/Pet_tracker_3/initz.lua b/DeepSleep/Pet_tracker_3/initz.lua index 60d980e..71605af 100644 --- a/DeepSleep/Pet_tracker_3/initz.lua +++ b/DeepSleep/Pet_tracker_3/initz.lua @@ -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() --[[ diff --git a/DeepSleep/Pet_tracker_3/wifi_init.lua b/DeepSleep/Pet_tracker_3/wifi_init.lua index 2a61c34..05f9727 100644 --- a/DeepSleep/Pet_tracker_3/wifi_init.lua +++ b/DeepSleep/Pet_tracker_3/wifi_init.lua @@ -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