Commencé à enregistrer dans la FS les connexions/déconnexions du socat afin de pouvoir mieux 'voir' les problèmes de reconnexions en boucle

This commit is contained in:
Christian Zufferey
2020-06-14 14:27:57 +02:00
parent 5b1af2e6bd
commit f08c3815db
4 changed files with 65 additions and 27 deletions

View File

@@ -1,6 +1,6 @@
-- Scripts qui permet d'enregistrer la raison du boot dans la flash
print("\n 0_rec_boot.lua zf200612.1117 \n")
print("\n 0_rec_boot.lua zf200614.1422 \n")
-- Problématique:
-- Afin de pouvoir enregistrer l'heure du boot dans la FLASH il faut
@@ -8,14 +8,14 @@ print("\n 0_rec_boot.lua zf200612.1117 \n")
-- faire l'enregistrement dans la FLASH
function rec_boot()
sntp.sync(nil, nil, nil, 1)
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
tmr_rec_boot1=tmr.create()
tmr_rec_boot1:alarm(1*1000, tmr.ALARM_AUTO, function()
if verbose then print("tmr_rec_boot1........................") end
@@ -23,25 +23,24 @@ function rec_boot()
if verbose then print(rtctime.get()) end
if verbose then print(ztime_format(rtctime.get()+3600)) end
if rtctime.get() > 0 then
print("Voilà on à l'heure, on peut enregistrer la raison du boot...")
tmr_rec_boot1:unregister() tmr_rec_boot1=nil
file.open("00_boot_reason.txt", "a+")
file.writeline(ztime_format(rtctime.get()+3600))
_, zboot_reason, zboot_detail = node.bootreason()
file.writeline(zboot_reason,zboot_detail)
local _, zboot_reason, zboot_detail = node.bootreason()
file.writeline("boot reason: "..zboot_reason)
file.close()
zboot_detail=nil zboot_reason=nil tm=nil
ztime_format=nil rec_boot=nil
collectgarbage() print(node.heap())
end
if verbose then print("End tmr_rec_boot1:") end
collectgarbage()
if verbose then print(node.heap()) end
end)
end
rec_boot()

View File

@@ -27,7 +27,7 @@ telnet -rN localhost 23000
]]
print("\n 0_tst4_socat.lua zf200613.1806 \n")
print("\n 0_tst4_socat.lua zf200614.1413 \n")
local node, table, tmr, uwrite, tostring =
node, table, tmr, uart.write, tostring
@@ -37,13 +37,6 @@ local function telnet_listener(socket)
table.insert, table.remove, table.concat, node.heap, collectgarbage
local fifo1, fifo1l, fifo2, fifo2l = {}, 0, {}, 0
local s -- s is a copy of the TCP socket if and only if sending is in progress
-- local wdclr, cnt = tmr.wdclr, 0
-- local function debug(fmt, ...)
-- if (...) then fmt = fmt:format(...) end
-- uwrite(0, "\r\nDBG: ",fmt,"\r\n" )
-- cnt = cnt + 1
-- if cnt % 10 then wdclr() end
-- end
local function flushGarbage()
if heap() < 13440 then gc() end
@@ -99,12 +92,11 @@ local function telnet_listener(socket)
end
local function disconnect(s)
--fifo1, fifo1l, fifo2, fifo2l, s = {}, 0, {}, 0, nil
debug_rec("disconnect, disconnected")
fifo1, fifo1l, fifo2, fifo2l, s = nil, nil, nil, nil, nil
--insert, remove, concat, heap, gc = nil, nil, nil, nil, nil
--wdclr, cnt = nil, nil
node.output(nil) srv_rt = nil
collectgarbage() print(node.heap())
print(tmr.now()/1000000-ztime_connect)
print("disconnected...")
if http_post~=nil then http_post(influxdb_url,"energy,memory=socat_disconnected_"..yellow_id.." ram="..node.heap()) end
print("rt_retry:",rt_retry)
@@ -120,13 +112,15 @@ local function telnet_listener(socket)
--zzz
local function zconnection(s)
print("Welcome on ne devrait jamais passer par là to NodeMCU world.")
debug_rec("zconnection, pas glop")
end
socket:on("connection", zconnection)
socket:on("receive", receiveLine)
socket:on("disconnection", disconnect)
socket:on("sent", sendLine)
node.output(queueLine, 0)
-- node.output(queueLine, 0)
node.output(queueLine, 1)
end
--net.createServer(net.TCP, 180):listen(23, telnet_listener)
@@ -137,8 +131,12 @@ print("Revers telnet server running...\n")
function rt_connect()
srv_rt = nil collectgarbage() srv_rt = net.createConnection(net.TCP, 0)
collectgarbage()
srv_rt = net.createConnection(net.TCP, 0)
srv_rt:on("connection", function(sck)
debug_rec("rt_connect, srv_rt:on, connected on")
ztime_connect=tmr.now()/1000000
collectgarbage()
-- if verbose then
gpio.write(zLED, gpio.LOW)
@@ -149,8 +147,11 @@ function rt_connect()
telnet_listener(sck)
print("Welcome to NodeMCU world.")
end)
srv_rt:connect(console_port,console_host)
debug_rec("rt_connect, try connect")
collectgarbage()
-- if verbose then
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
print("trying connect to "..console_host..":"..console_port)
@@ -196,9 +197,16 @@ rt_connect()
print(srv_rt)
print(srv_rt:getpeer())
rt_connect=nil
telnet_listener=nil
disconnect=nil
total_allocated, estimated_used = node.egc.meminfo()
print(total_allocated, estimated_used)
print(console_port)
srv_rt = nil collectgarbage()
tmr_socat1:unregister()
for k,v in pairs(_G) do print(k,v) end

View File

@@ -0,0 +1,16 @@
node.stripdebug(3)
node.compile('0_tst4_socat.lua')
rt_connect()
print(srv_rt)
print(srv_rt:getpeer())
total_allocated, estimated_used = node.egc.meminfo()
print(total_allocated, estimated_used)
print(console_port)
srv_rt = nil collectgarbage()

View File

@@ -1,6 +1,20 @@
-- Scripts à charger après le boot pour démarrer son projet
print("\n boot.lua zf200612.0936 \n")
print("\n boot.lua zf200614.1424 \n")
function zztime_format(ztime)
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
function debug_rec(zdebug)
local sec, usec = rtctime.get()
file.open("00_boot_reason.txt", "a+")
file.writeline(zztime_format(sec).."."..usec..", "..zdebug)
file.close()
end
function boot()
verbose = false
@@ -9,7 +23,7 @@ function boot()
f = "0_rec_boot.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())
@@ -39,6 +53,7 @@ function boot()
end
boot()
--[[
verbose = true
verbose = false