Ca commence à marcher en reconnexion automatique, mais maintenant c'est mon 'serveur' telnet local qui est trop simpliste :-(

This commit is contained in:
Christian Zufferey
2020-02-09 16:37:35 +01:00
parent b155f1e812
commit 53d5028a72
2 changed files with 28 additions and 26 deletions

View File

@@ -5,10 +5,10 @@ socat TCP-LISTEN:23002,fork,reuseaddr STDIO
socat TCP-LISTEN:23002,reuseaddr,fork TCP-LISTEN:24002,reuseaddr
]]
print("\n 0_tst2_socat.lua zf200209.1442 \n")
print("\n 0_tst2_socat.lua zf200209.1615 \n")
srv_rt = net.createConnection(net.TCP, 0)
srv_rt:connect(console_port,console_host)
srv_rt:on("connection", function(sck)
print("c'est connected...")
@@ -30,7 +30,20 @@ srv_rt:on("connection", function(sck)
--unregist redirect output function, output goes to serial
end)
print("Welcome to NodeMcu world.")
end)
tmr_socat1=tmr.create()
tmr_socat1:alarm(1*1000, tmr.ALARM_AUTO , function()
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
if console_port == srv_rt:getpeer() then
gpio.write(zLED, gpio.LOW)
else
gpio.write(zLED, gpio.HIGH)
print("trying...")
srv_rt:connect(console_port,console_host)
end
end)
@@ -38,35 +51,18 @@ end)
--[[
print(srv:getpeer())
print(srv_rt:getpeer())
if console_port == srv:getpeer() then
srv_rt:connect(console_port,console_host)
gpio.write(zLED, gpio.LOW) tmr.delay(10000) gpio.write(zLED, gpio.HIGH)
if console_port == srv_rt:getpeer() then
gpio.write(zLED, gpio.LOW)
else
gpio.write(zLED, gpio.HIGH)
end
s=net.createServer(net.TCP,180)
s:listen(2323,function(c)
function s_output(str)
if(c~=nil)
then c:send(str)
end
end
node.output(s_output, 0)
-- re-direct output to function s_ouput.
c:on("receive",function(c,l)
node.input(l)
--like pcall(loadstring(l)), support multiple separate lines
end)
c:on("disconnection",function(c)
node.output(nil)
--unregist redirect output function, output goes to serial
end)
print("Welcome to NodeMcu world.")
end)
]]

View File

@@ -1,5 +1,5 @@
-- fonction cat() pour afficher le contenu d'un fichier dans la flash
print("\n cat.lua zf191124.2204 \n")
print("\n cat.lua zf200209.1630 \n")
function zread_line()
local zline = ""
@@ -15,7 +15,13 @@ function cat(zfile)
zf = file.open(zfile, "r")
while true do
zline = zread_line() if zline == nil then break end
tmr.delay(100*1000)
print(zline)
end
zf:close()
print("-------------------------------")