From f08c3815db3e7a106415a2956f369325ca066510 Mon Sep 17 00:00:00 2001 From: Christian Zufferey Date: Sun, 14 Jun 2020 14:27:57 +0200 Subject: [PATCH] =?UTF-8?q?Commenc=C3=A9=20=C3=A0=20enregistrer=20dans=20l?= =?UTF-8?q?a=20FS=20les=20connexions/d=C3=A9connexions=20du=20socat=20afin?= =?UTF-8?q?=20de=20pouvoir=20mieux=20'voir'=20les=20probl=C3=A8mes=20de=20?= =?UTF-8?q?reconnexions=20en=20boucle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../transfo_courant_clip_1p_1/0_rec_boot.lua | 21 ++++++----- .../0_tst4_socat.lua | 36 +++++++++++-------- .../transfo_courant_clip_1p_1/_zlocal_cmd.txt | 16 +++++++++ .../energy/transfo_courant_clip_1p_1/boot.lua | 19 ++++++++-- 4 files changed, 65 insertions(+), 27 deletions(-) create mode 100644 Mesures/energy/transfo_courant_clip_1p_1/_zlocal_cmd.txt diff --git a/Mesures/energy/transfo_courant_clip_1p_1/0_rec_boot.lua b/Mesures/energy/transfo_courant_clip_1p_1/0_rec_boot.lua index 6f02203..f6588e5 100644 --- a/Mesures/energy/transfo_courant_clip_1p_1/0_rec_boot.lua +++ b/Mesures/energy/transfo_courant_clip_1p_1/0_rec_boot.lua @@ -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() diff --git a/Mesures/energy/transfo_courant_clip_1p_1/0_tst4_socat.lua b/Mesures/energy/transfo_courant_clip_1p_1/0_tst4_socat.lua index d73b9ec..1a8c615 100644 --- a/Mesures/energy/transfo_courant_clip_1p_1/0_tst4_socat.lua +++ b/Mesures/energy/transfo_courant_clip_1p_1/0_tst4_socat.lua @@ -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 diff --git a/Mesures/energy/transfo_courant_clip_1p_1/_zlocal_cmd.txt b/Mesures/energy/transfo_courant_clip_1p_1/_zlocal_cmd.txt new file mode 100644 index 0000000..ae6ce27 --- /dev/null +++ b/Mesures/energy/transfo_courant_clip_1p_1/_zlocal_cmd.txt @@ -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() + + diff --git a/Mesures/energy/transfo_courant_clip_1p_1/boot.lua b/Mesures/energy/transfo_courant_clip_1p_1/boot.lua index 8a1232b..ed5b85f 100644 --- a/Mesures/energy/transfo_courant_clip_1p_1/boot.lua +++ b/Mesures/energy/transfo_courant_clip_1p_1/boot.lua @@ -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