Post your best Lua script examples here

User avatar
By sigrokBlack
#17329 Hi,
I want to connect 2 Esp to a wireless uart,but it isn't working.
Main:
Code: Select all--uart.setup(0,9600,8,0,1,0)
tmr.delay(2000000)
conn=net.createConnection(net.TCP, false)

global_c = nil

conn:on("receive",function(c)
     if global_c~=nil then
          global_c:close()
     end
     global_c=c
      c:on("receive", function(c, pl) print(pl) end)
      --c:send("hello world")
     end)

uart.on("data","\r", function(data)
     if global_c~=nil then
          global_c:send(data)
     end
     --uart.write(0,data)
end, 0)

conn:connect(80,'192.168.4.1')


Other module:
Code: Select all--uart.setup(0,115200,8,0,1,0)
uart.setup(0,9600,8,0,1,0)
sv=net.createServer(net.TCP, 240)

global_c = nil

sv:listen(80,function(c)
     if global_c~=nil then
          global_c:close()
     end
     global_c=c
      c:on("receive", function(c, pl) print(pl) end)
      --c:send("hello world")
     end)

uart.on("data","\r", function(data)
     if global_c~=nil then
          global_c:send(data)
     end
     --uart.write(0,data)
end, 0)



What can I do?
User avatar
By TerryE
#17557 Don't use tmr.delay for this. See my topic on this for an exlanation.

Start wit the telnet example in the distro and build on that.