Ca marche mieux mais ce n'est pas encore cela, cela reboote toutes les 15mn maintenant :-(

This commit is contained in:
Christian Zufferey
2020-06-15 19:32:33 +02:00
parent 514e42806f
commit 42b137a2d3
6 changed files with 99 additions and 85 deletions

View File

@@ -1,21 +1,21 @@
-- Petit script pour faire office de crontab pour les mesures
print("\n 0_cron.lua zf200610.1838 \n")
print("\n 0_cron.lua zf200615.1605 \n")
cron1=tmr.create()
cron1:alarm(10*1000, tmr.ALARM_AUTO, function()
if verbose then print("cron1........................") end
if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end
http_post(influxdb_url,"energy,value=test1_"..yellow_id.." val=1")
-- http_post(influxdb_url,"energy,value=test1_"..yellow_id.." val=1")
http_post(influxdb_url,"energy,memory=cron1_"..yellow_id.." ram="..node.heap())
if yellow_id == 60 then http_post(influxdb_url,"energy,compteur=3 puissance="..zpower/1000) end
if yellow_id == 64 then http_post(influxdb_url,"energy,compteur=4 puissance="..zpower/1000) end
-- if yellow_id == 60 then http_post(influxdb_url,"energy,compteur=3 puissance="..zpower/1000) end
-- if yellow_id == 64 then http_post(influxdb_url,"energy,compteur=4 puissance="..zpower/1000) end
http_post(influxdb_url,"energy,value=test2_"..yellow_id.." val=2")
http_post(influxdb_url,"energy,value=test3_"..yellow_id.." val=3")
http_post(influxdb_url,"energy,value=test4_"..yellow_id.." val=4")
-- http_post(influxdb_url,"energy,value=test2_"..yellow_id.." val=2")
-- http_post(influxdb_url,"energy,value=test3_"..yellow_id.." val=3")
-- http_post(influxdb_url,"energy,value=test4_"..yellow_id.." val=4")
-- f = "0_zdyndns.lua" if file.exists(f) then dofile(f) end

View File

@@ -1,6 +1,6 @@
-- Scripts qui permet d'enregistrer la raison du boot dans la flash
print("\n 0_rec_boot.lua zf200614.1735 \n")
print("\n 0_rec_boot.lua zf200614.1851 \n")
-- Problématique:
-- Afin de pouvoir enregistrer l'heure du boot dans la FLASH il faut
@@ -12,7 +12,7 @@ function rec_boot()
sntp.sync(nil, nil, nil, 1)
function ztime_format(ztime)
local tm = rtctime.epoch2cal(ztime + 3600)
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

View File

@@ -27,7 +27,7 @@ telnet -rN localhost 23000
]]
print("\n 0_tst4_socat.lua zf200614.1732 \n")
print("\n 0_tst4_socat.lua zf200615.1850 \n")
local node, table, tmr, uwrite, tostring =
node, table, tmr, uart.write, tostring
@@ -58,7 +58,12 @@ local function telnet_listener(socket)
(remove(fifo2,1) or '') .. (remove(fifo2,1) or '')
fifo2l = fifo2l - #rec
flushGarbage()
s:send(rec)
--zzz
if srv_rt~=nil then
if console_port == srv_rt:getpeer() then
s:send(rec)
end
end
end
local F1_SIZE = 256
@@ -91,46 +96,44 @@ local function telnet_listener(socket)
node.input(line)
end
local function disconnect(s)
debug_rec("disconnect, disconnected")
local function disconnect(_,zerr)
node.output(nil)
gpio.write(zLED, gpio.HIGH)
fifo1, fifo1l, fifo2, fifo2l, s = nil, nil, nil, 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)
rt_retry=rt_retry-1
print("rt_retry:",rt_retry)
if rt_retry>=0 then
print("on ressaie en vitesse une fois ;-)")
rt_connect()
collectgarbage() print("disconnected... "..zerr..", "..node.heap())
if debug_rec~=nil then debug_rec("disconnect, disconnected, "..zerr..", "..node.heap()) end
local zlaps=tmr.now()/1000000-ztime_connect
print("durée de connexion... "..zlaps)
if debug_rec~=nil then debug_rec("durée de connexion... "..zlaps..", "..node.heap()) end
if zlaps>1 then
-- if http_post~=nil then http_post(influxdb_url,"energy,memory=socat_disconnected_"..yellow_id.." ram="..node.heap()) end
print("rt_retry:",rt_retry)
rt_retry=rt_retry-1
print("rt_retry:",rt_retry)
if rt_retry>=0 then
local zstr="disconnect, reconnect 1x, "..node.heap()
print(zstr) if debug_rec~=nil then debug_rec(zstr) end
rt_connect()
end
end
end
--zzz
local function zconnection(s)
local zstr="zconnection, Welcome on ne devrait jamais passer par là to NodeMCU world."
print(zstr) debug_rec(zstr)
print(zstr) if debug_rec~=nil then debug_rec(zstr) end
end
--zzz
local function zreconnection(s)
local zstr="zreconnection, Oups... pourquoi ici ?"
print(zstr) debug_rec(zstr)
end
socket:on("connection", zconnection)
socket:on("receive", receiveLine)
socket:on("disconnection", disconnect)
socket:on("reconnection", zreconnection)
socket:on("sent", sendLine)
-- node.output(queueLine, 0)
node.output(queueLine, 1)
node.output(queueLine, 0)
-- node.output(queueLine, 1)
end
--net.createServer(net.TCP, 180):listen(23, telnet_listener)
@@ -141,61 +144,62 @@ print("Revers telnet server running...\n")
function rt_connect()
collectgarbage()
srv_rt = nil collectgarbage()
srv_rt = net.createConnection(net.TCP, 0)
srv_rt:on("connection", function(sck)
debug_rec("rt_connect, srv_rt:on, connected on")
if debug_rec~=nil then debug_rec("rt_connect, srv_rt:on, connected on, "..node.heap()) end
ztime_connect=tmr.now()/1000000
collectgarbage()
-- if verbose then
gpio.write(zLED, gpio.LOW)
print("connected on "..console_host..":"..console_port)
print(node.heap())
-- end
-- if verbose then
gpio.write(zLED, gpio.LOW)
print("connected on "..console_host..":"..console_port)
print(node.heap())
-- end
if http_post~=nil then http_post(influxdb_url,"energy,memory=socat_connected_"..yellow_id.." ram="..node.heap()) end
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)
print(node.heap())
-- end
srv_rt:connect(console_port,console_host)
collectgarbage()
-- if debug_rec~=nil then debug_rec("rt_connect, try connect, "..node.heap()) end
-- if verbose then
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
print("trying connect to "..console_host..":"..console_port)
print(node.heap())
-- end
if http_post~=nil then http_post(influxdb_url,"energy,memory=socat_try_con_"..yellow_id.." ram="..node.heap()) end
end
-- tmr_socat1=tmr.create()
-- tmr_socat1:alarm(15*1000, tmr.ALARM_AUTO , function()
--
-- if http_post~=nil then http_post(influxdb_url,"energy,memory=tmr_socat1_"..yellow_id.." ram="..node.heap()) end
--
-- -- rt_retry=1
-- -- if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end
-- if srv_rt~=nil then
--
-- if http_post~=nil then http_post(influxdb_url,"energy,memory=srv_rt_no_nil_"..yellow_id.." ram="..node.heap()) end
--
-- if console_port ~= srv_rt:getpeer() then
-- --on relance...
-- rt_connect()
-- end
-- else
-- --on relance...
-- rt_connect()
-- end
-- end)
tmr_socat1=tmr.create()
tmr_socat1:alarm(15*1000, tmr.ALARM_AUTO , function()
if http_post~=nil then http_post(influxdb_url,"energy,memory=tmr_socat1_"..yellow_id.." ram="..node.heap()) end
rt_retry=3
-- if verbose then gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH) end
if srv_rt~=nil then
-- if http_post~=nil then http_post(influxdb_url,"energy,memory=srv_rt_no_nil_"..yellow_id.." ram="..node.heap()) end
if console_port ~= srv_rt:getpeer() then
--on relance...
rt_connect()
end
else
--on relance...
rt_connect()
end
end)
rt_retry=1
--rt_connect()
rt_retry=3
rt_connect()

View File

@@ -1,3 +1,5 @@
zf200615.1932
node.stripdebug(3)
node.compile('0_tst4_socat.lua')
@@ -5,6 +7,10 @@ rt_connect()
print(srv_rt)
print(srv_rt:getpeer())
node.output(nil)
=srv_rt:getaddr()
srv_rt:close()
total_allocated, estimated_used = node.egc.meminfo()
print(total_allocated, estimated_used)

View File

@@ -1,5 +1,5 @@
# Quelques commandes remote (luatool) à envoyer avec le plugin Atom-IDE-terminal de l'éditeur Atom
# zf200612.1624
# zf200615.1725
Todo à faire pour ce projet !
@@ -78,17 +78,22 @@ for k,v in pairs(_G) do print(k,v) end
################################
killall -9 ssh
ssh ubuntu@www.zuzu-test.ml killall -9 socat
#ssh ubuntu@www.zuzu-test.ml socat TCP-LISTEN:23060,reuseaddr,fork TCP-LISTEN:23000,reuseaddr,bind=127.0.0.1 &
ssh ubuntu@www.zuzu-test.ml socat TCP-LISTEN:23064,reuseaddr,fork TCP-LISTEN:23000,reuseaddr,bind=127.0.0.1 &
# SHIFT+CMD+K SHIFT+CMD+K ALT+CMD+F
watch -n 1 'ssh ubuntu@www.zuzu-test.ml netstat -nat |grep 230'
# ALT+CMD+F CTRL+C ALT+CMD+F
ssh -N -L 23000:localhost:23000 ubuntu@www.zuzu-test.ml &
export zIP="localhost"
export zport="23000"
ssh -N -L 23000:localhost:23000 ubuntu@www.zuzu-test.ml &
telnet -rN $zIP $zport
=node.heap()
~.
verbose=false
= node.bootreason()
@@ -96,7 +101,6 @@ verbose=false
for k,v in pairs(_G) do print(k,v) end
verbose=true
~.
#zdyn
./luatool.py --ip $zIP:$zport -f boot.lua

View File

@@ -1,9 +1,9 @@
-- Scripts à charger après le boot pour démarrer son projet
print("\n boot.lua zf200614.1724 \n")
print("\n boot.lua zf200615.1852 \n")
function zztime_format(ztime)
local tm = rtctime.epoch2cal(ztime + 3600)
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
@@ -40,8 +40,8 @@ function boot()
collectgarbage() print(node.heap())
zpower=0
f="0_get_power.lua" if file.exists(f) then dofile(f) end
collectgarbage() print(node.heap())
-- f="0_get_power.lua" if file.exists(f) then dofile(f) end
-- collectgarbage() print(node.heap())
f="0_cron.lua" if file.exists(f) then dofile(f) end
collectgarbage() print(node.heap())