Refactorisé complètement mon boot.lua, le debug recording avec timestamp fait partie maintenant du boot !
This commit is contained in:
@@ -1,37 +1,17 @@
|
||||
-- Scripts à charger après le boot pour démarrer son projet
|
||||
|
||||
print("\n boot.lua zf200615.2226 \n")
|
||||
|
||||
-- function zztime_format(ztime)
|
||||
-- local tm = rtctime.epoch2cal(ztime + 2*3600)
|
||||
-- return(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]))
|
||||
-- end
|
||||
--
|
||||
-- function debug_rec(zdebug)
|
||||
-- local sec, usec = rtctime.get()
|
||||
-- file.open("00_debug.txt", "a+")
|
||||
-- file.writeline(zztime_format(sec).."."..usec..", "..zdebug)
|
||||
-- file.close()
|
||||
-- end
|
||||
|
||||
|
||||
|
||||
function boot()
|
||||
verbose = false
|
||||
print("\n boot.lua zf200616.1613 \n")
|
||||
print("On lance le boot...")
|
||||
collectgarbage() print(node.heap())
|
||||
|
||||
f = "0_rec_boot.lua" if file.exists(f) then dofile(f) end
|
||||
local f
|
||||
f = "0_http_post.lua" if file.exists(f) then dofile(f) end
|
||||
collectgarbage() print(node.heap())
|
||||
|
||||
-- f = "0_http_post.lua" if file.exists(f) then dofile(f) end
|
||||
-- collectgarbage() print(node.heap())
|
||||
function http_post() local z end
|
||||
|
||||
-- local _, boot_reason = node.bootreason()
|
||||
-- zarg_boot= "energy,memory=boot_"..yellow_id.." ram="..node.heap().."\n"
|
||||
-- zarg_boot=zarg_boot.."energy,value=boot_reason_"..yellow_id.." val="..boot_reason
|
||||
-- http_post(influxdb_url,zarg_boot)
|
||||
local _, boot_reason = node.bootreason()
|
||||
zarg_boot= "energy,memory=boot_"..yellow_id.." ram="..node.heap().."\n"
|
||||
zarg_boot=zarg_boot.."energy,value=boot_reason_"..yellow_id.." val="..boot_reason
|
||||
http_post(influxdb_url,zarg_boot)
|
||||
|
||||
-- f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end
|
||||
-- print(node.heap()) collectgarbage() print(node.heap())
|
||||
@@ -46,12 +26,38 @@ function boot()
|
||||
-- f="0_cron.lua" if file.exists(f) then dofile(f) end
|
||||
-- collectgarbage() print(node.heap())
|
||||
|
||||
print("verbose:",verbose) print("le boot est lancé...")
|
||||
verbose = false
|
||||
print("verbose: ",verbose,"\nle boot est lancé...")
|
||||
gpio.write(zLED, gpio.HIGH)
|
||||
f=nil boot=nil
|
||||
collectgarbage() print(node.heap())
|
||||
boot=nil
|
||||
end
|
||||
|
||||
function debug_rec(zdebug)
|
||||
local sec, usec = rtctime.get() local tm = rtctime.epoch2cal(sec + 2*3600)
|
||||
local ztm = string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"])
|
||||
file.open("00_debug.txt", "a+") file.writeline(ztm.."."..usec..", "..zdebug) file.close()
|
||||
end
|
||||
|
||||
function rec_boot()
|
||||
sntp.sync(nil, nil, nil, 1)
|
||||
tmr_rec_boot1=tmr.create()
|
||||
tmr_rec_boot1:alarm(1*1000, tmr.ALARM_AUTO, function()
|
||||
print("beep...")
|
||||
if rtctime.get() > 0 then
|
||||
tmr_rec_boot1:unregister()
|
||||
print("Voilà on à l'heure, on peut enregistrer la raison du boot...")
|
||||
local _, zboot_reason, zboot_detail = node.bootreason()
|
||||
debug_rec("boot reason: "..zboot_reason)
|
||||
tmr_rec_boot1=nil rec_boot=nil
|
||||
collectgarbage() print(node.heap())
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
verbose=true
|
||||
rec_boot()
|
||||
boot()
|
||||
collectgarbage() print(node.heap())
|
||||
|
||||
|
||||
--[[
|
||||
|
||||
@@ -1,22 +1,14 @@
|
||||
-- Scripts qui permet d'enregistrer la raison du boot dans la flash
|
||||
|
||||
print("\n 0_rec_boot.lua zf200615.2229 \n")
|
||||
|
||||
-- Problématique:
|
||||
-- Afin de pouvoir enregistrer l'heure du boot dans la FLASH il faut
|
||||
-- en premier récupérer l'heure sur Internet et après seulement on peut
|
||||
-- faire l'enregistrement dans la FLASH
|
||||
|
||||
function rec_boot()
|
||||
|
||||
sntp.sync(nil, nil, nil, 1)
|
||||
|
||||
function ztime_format(ztime)
|
||||
local tm = rtctime.epoch2cal(ztime + 2*3600)
|
||||
return(string.format("%04d/%02d/%02d %02d:%02d:%02d", tm["year"], tm["mon"], tm["day"], tm["hour"], tm["min"], tm["sec"]))
|
||||
end
|
||||
|
||||
tmr_rec_boot1=tmr.create()
|
||||
print("\n 0_rec_boot.lua zf200616.1400 \n")
|
||||
|
||||
local tmr_rec_boot1=tmr.create()
|
||||
tmr_rec_boot1:alarm(1*1000, tmr.ALARM_AUTO, function()
|
||||
if verbose then print("tmr_rec_boot1........................") end
|
||||
if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end
|
||||
@@ -25,15 +17,11 @@ function rec_boot()
|
||||
if verbose then print(ztime_format(rtctime.get()+3600)) end
|
||||
|
||||
if rtctime.get() > 0 then
|
||||
tmr_rec_boot1:unregister()
|
||||
print("Voilà on à l'heure, on peut enregistrer la raison du boot...")
|
||||
tmr_rec_boot1:unregister() tmr_rec_boot1=nil
|
||||
local sec, usec = rtctime.get()
|
||||
local _, zboot_reason, zboot_detail = node.bootreason()
|
||||
file.open("00_debug.txt", "a+")
|
||||
file.writeline(string.rep(".",20))
|
||||
file.writeline(ztime_format(sec).."."..usec..", boot reason: "..zboot_reason)
|
||||
file.close()
|
||||
ztime_format=nil rec_boot=nil
|
||||
debug_rec("boot reason: "..zboot_reason)
|
||||
tmr_rec_boot1=nil rec_boot=nil
|
||||
collectgarbage() print(node.heap())
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user