- complètement remanié le script de boot init.lua. Maintenant il tient compte de la cause du reboot, et si c'est un poweron, démarre le script repair.lua au lieu de boot.lua

- renommé le script start_job.lua en boot.lua, script qui est lancé par init.lua juste après le boot
- créé le script repair.lua qui démarre le wifi en mode AP et lance le serveur telnet afin de pouvoir se connecter au moment du poweron si on a un problème de boucle au boot
- mon script dsleep.lua fonctionne bien maintenant
- amélioré le script wifi_info.lua, il indique le nom de l'AP ainsi que le password
- teste à chaque 'dofile' si le fichier existe avant de la lancer, ne plante donc plus si le script n'existe pas, grosse amélioration
This commit is contained in:
Christian Zufferey
2018-11-19 00:30:08 +01:00
parent b2b632a6cd
commit 8b78b4aa04
33 changed files with 337 additions and 93 deletions

View File

@@ -0,0 +1,21 @@
-- super mini bootstrap
print("\n init_minizf1.lua zf180909.1112 \n")
zswitch=3 --switch flash
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
initalarme=tmr.create()
function zbutton()
gpio.trig(zswitch, "none")
tmr.unregister(initalarme)
dofile("start_boot.lua")
dofile("start_job.lua")
end
gpio.trig(zswitch, "both", zbutton)
tmr.alarm(initalarme, 8000, tmr.ALARM_SINGLE, function()
print("\nStart\n")
dofile("start_boot.lua")
-- dofile("start_job.lua")
end)

View File

@@ -0,0 +1,90 @@
-- initz.lua
-- test si clic sur le bouton
-- clic <2s goto start.lua
-- clic >2s goto config wifi
print("\ninit.lua zf180719.1100 \n")
zBTNz = 3 -- GPIO0 button
--zRelay = 6 -- GPIO12 PWM0 relay (active high)
zLEDz = 0 -- SonOff: 7 GPIO13 PWM1, NodeMCU: 0, (active low)
zFlag_LEDz = 0
function blink_LEDz ()
if zFlag_LEDz==gpio.LOW then
zFlag_LEDz=gpio.HIGH
tmr.alarm(ztmr_LEDz, zTm_Off_LEDz, tmr.ALARM_SINGLE, blink_LEDz)
else
zFlag_LEDz=gpio.LOW
tmr.alarm(ztmr_LEDz, zTm_On_LEDz, tmr.ALARM_SINGLE, blink_LEDz)
end
gpio.write(zLEDz, zFlag_LEDz)
end
gpio.mode(zLEDz, gpio.OUTPUT)
ztmr_LEDz = tmr.create()
zTm_On_LEDz = 500
zTm_Off_LEDz = 500
blink_LEDz ()
function btn_testz()
t2z=tmr.now()
t3z=(t2z-t1z)/1000000
if gpio.read(zBTNz)==1 then
tmr.stop(0)
gpio.trig(zBTNz)
tmr.stop(ztmr_LEDz)
gpio.write(zLEDz,1)
print("start.lua")
ztmr_clear_bootstrapz = tmr.create()
-- tmr.alarm(ztmr_clear_bootstrapz,1000,tmr.ALARM_SINGLE, function() dofile("clear_bootstrap.lua") end)
dofile("start.lua")
end
if t3z>2 then
tmr.stop(0)
gpio.trig(zBTNz)
zTm_On_LEDz = 100
zTm_Off_LEDz = 100
blink_LEDz ()
wifi.sta.disconnect()
wifi.sta.clearconfig()
print("\nwifi config http://192.168.4.1\n")
tmr.alarm(0, 1000, tmr.ALARM_AUTO , get_ipz)
enduser_setup.start()
end
end
function btn_clicz()
t1z=tmr.now()
tmr.stop(ztmr_LEDz)
gpio.write(zLEDz,0)
tmr.alarm(0,100,tmr.ALARM_AUTO, btn_testz)
end
function get_ipz()
if wifi.sta.getip() == nil then
print("Connecting to AP...")
else
tmr.stop(0)
print("Connected! IP: ",wifi.sta.getip())
tmr.alarm(0,4000,tmr.ALARM_SINGLE, function() node.restart() end)
end
end
function dir()
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('\nUsed: '..i..' bytes\nusage: dofile("file.lua")\n')
end
gpio.mode(zBTNz,gpio.INT)
gpio.trig(zBTNz, "down", btn_clicz)
wifi.sta.connect()
dofile("telnet_srv.lua")

View File

@@ -0,0 +1,90 @@
-- initz.lua
-- test si clic sur le bouton
-- clic <2s goto start.lua
-- clic >2s goto config wifi
print("\ninit.lua zf180719.1045 \n")
zBTN = 3 -- GPIO0 button
--zRelay = 6 -- GPIO12 PWM0 relay (active high)
zLED = 0 -- SonOff: 7 GPIO13 PWM1, NodeMCU: 0, (active low)
zFlag_LED = 0
function blink_LED ()
if zFlag_LED==gpio.LOW then
zFlag_LED=gpio.HIGH
tmr.alarm(ztmr_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED)
else
zFlag_LED=gpio.LOW
tmr.alarm(ztmr_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED)
end
gpio.write(zLED, zFlag_LED)
end
gpio.mode(zLED, gpio.OUTPUT)
ztmr_LED = tmr.create()
zTm_On_LED = 500
zTm_Off_LED = 500
blink_LED ()
function btn_test()
t2=tmr.now()
t3=(t2-t1)/1000000
if gpio.read(zBTN)==1 then
tmr.stop(0)
gpio.trig(zBTN)
tmr.stop(ztmr_LED)
gpio.write(zLED,1)
print("start.lua")
ztmr_clear_bootstrap = tmr.create()
tmr.alarm(ztmr_clear_bootstrap,1000,tmr.ALARM_SINGLE, function() dofile("clear_bootstrap.lua") end)
dofile("start.lua")
end
if t3>2 then
tmr.stop(0)
gpio.trig(zBTN)
zTm_On_LED = 100
zTm_Off_LED = 100
blink_LED ()
wifi.sta.disconnect()
wifi.sta.clearconfig()
print("\nwifi config http://192.168.4.1\n")
tmr.alarm(0, 1000, tmr.ALARM_AUTO , get_ip)
enduser_setup.start()
end
end
function btn_clic()
t1=tmr.now()
tmr.stop(ztmr_LED)
gpio.write(zLED,0)
tmr.alarm(0,100,tmr.ALARM_AUTO, btn_test)
end
function get_ip()
if wifi.sta.getip() == nil then
print("Connecting to AP...")
else
tmr.stop(0)
print("Connected! IP: ",wifi.sta.getip())
tmr.alarm(0,4000,tmr.ALARM_SINGLE, function() node.restart() end)
end
end
function dir()
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('\nUsed: '..i..' bytes\nusage: dofile("file.lua")\n')
end
gpio.mode(zBTN,gpio.INT)
gpio.trig(zBTN, "down", btn_clic)
wifi.sta.connect()
dofile("telnet_srv.lua")

View File

@@ -0,0 +1,23 @@
--Script de bootstrap, en appuyant sur le bouton ça démarre start_boot,
-- autrement en attendant 8 secondes cela démarre start_boot
print("\n init.lua zf181017.1026\n")
zswitch=3 --switch flash
gpio.mode(zswitch, gpio.INT, gpio.PULLUP)
initalarme=tmr.create()
function hvbouton()
gpio.trig(zswitch, "none")
tmr.unregister(initalarme)
dofile("start_boot.lua")
-- dofile("start_job.lua")
end
gpio.trig(zswitch, "both", hvbouton)
tmr.alarm(initalarme, 8000, tmr.ALARM_SINGLE, function()
print("\nStart\n")
dofile("start_boot.lua")
-- dofile("start_job.lua")
end)

View File

@@ -0,0 +1,27 @@
-- start.lua
-- programme de start
-- zf180719.1057
do
local zLED=0
local zTm_On_LED = 100 --> en ms
local zTm_Off_LED = 900 --> en ms
local zFlag_LED = 0
local function blink_LED ()
local ztmr_LED = tmr.create()
if zFlag_LED==gpio.LOW then
zFlag_LED=gpio.HIGH
tmr.alarm(ztmr_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED)
else
zFlag_LED=gpio.LOW
tmr.alarm(ztmr_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED)
end
gpio.write(zLED, zFlag_LED)
end
gpio.mode(zLED, gpio.OUTPUT)
blink_LED ()
end

View File

@@ -0,0 +1,23 @@
-- start.lua
-- programme de start
-- zf180717.1141
zLED=0
zTm_On_LED = 100 --> en ms
zTm_Off_LED = 900 --> en ms
zFlag_LED = 0
function blink_LED ()
if zFlag_LED==gpio.LOW then
zFlag_LED=gpio.HIGH
tmr.alarm(ztmr_LED, zTm_Off_LED, tmr.ALARM_SINGLE, blink_LED)
else
zFlag_LED=gpio.LOW
tmr.alarm(ztmr_LED, zTm_On_LED, tmr.ALARM_SINGLE, blink_LED)
end
gpio.write(zLED, zFlag_LED)
end
gpio.mode(zLED, gpio.OUTPUT)
ztmr_LED = tmr.create()
blink_LED()

View File

@@ -0,0 +1,7 @@
-- Scripts à charger au moment du boot
print("\n start_boot.lua zf181017.1021 \n")
dofile("blink_led1.lua")

View File

@@ -0,0 +1,4 @@
-- Permet de démarrer une petite démo simplement via telnet
print("\n start_demo1.lua zf180824.2027 \n")
dofile("oled_disp_multi_lines.lua")

View File

@@ -0,0 +1,7 @@
-- Scripts à charger après le boot pour démarrer son appli
print("\n start_job.lua zf180909.1117 \n")
jobtimer1=tmr.create()
jobtimer2=tmr.create()

View File

@@ -0,0 +1,13 @@
-- stop.lua
-- programme de stop
-- zf180716.0010
zBTN = 3 -- GPIO0 button
zRelay = 6 -- GPIO12 PWM0 relay (active high)
zLED = 7 -- GPIO13 PWM1 GREEN LED (active low)
gpio.mode(zLED,gpio.OUTPUT)
pwm.stop(zLED)
gpio.write(zLED,1)