As the title says... Chat on...

User avatar
By shaolin30
#48563 Hi everyone, I'm a total newbie about scripting in lua so please have patience with me.

My question is, I already have a init.lua and server.lua files uploaded to my esp8266-01 version. The script used to serve as a server and set as
Code: Select allwifi.SOFTAP
and this is my server.lua files:
Code: Select all--uart.setup(0,9600,8,0,1,0)
sv=net.createServer(net.TCP, 60)
global_c = nil
sv:listen(9999, function(c)
    if global_c~=nil then
        global_c:close()
    end
    global_c=c
    c:on("receive", function(sck,pl)    uart.write(0,pl) end)
end)

--this code used to print the data received from the client
uart.on("data", 4, function(data))
    if global_c~=nil then
        global_c:send(data)
    end
end, 0)


My question is, when I connect the GPIO0 with LED, the LED is on even though there's no client connected. What I want is I want the GPIO0 pin to use as an indicator if the ESP is connected to a client then the LED will be on and will be off if the client is disconnected. I need some help how can I achieve it using LUA script. Any help will be much appreciated. Thank you so much.