Current Lua downloadable firmware will be posted here

User avatar
By jeroen1978
#83615 Hi,

I'm not familiar with programming (but I've always wanted to learn), seached anywhere on the internet but I can't get this project to work.
I've installed NodeMCU and the script is made in LUA.

I want to use 2 ESP-01's, one as a accesspoint and one as a client (maybe a couple of more clients later).

I want to transmit serial data (TTL-3,3V) from one ESP-01 to the other ESP-01 and vice versa and want to use a TCP-connection.
So when I send serial data to the TX-pin of module 1, I want it to come out of the RX-pin of module 2 and when I send serial data to the TX-pin of module 2, I want it to come out of the RX-pin of module 1.

Because the data is going to be offered from one I/O-line the RX/TX pins will be connected to eachother so at the moment data is received from the RX-pin, the TX-pin of the same module must be temporary blocked.

Could somebody tell me what's wrong?

Script for the ACCESSPOINT:
-- ESP8266 Server
do
wifi.setmode(wifi.STATIONAP)
wifi.ap.config({ssid="ESP01",pwd="password"})

uart.setup(0, 9600, 8, 0, 1, 0)
sv=net.createServer(net.TCP, 80)
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)

uart.on("data",4, function(data)
if global_c~=nil then
global_c:send(data)
end
end, 0)
end

Script for the CLIENT:
-- ESP8266 Client
do
wifi.sta.disconnect()
wifi.setmode(wifi.STATION)
wifi.sta.config("ESP01","password") -- connecting to server
wifi.sta.connect()

uart.setup(0, 9600, 8, 0, 1, 0)
sv=net.createServer(net.TCP, 80)
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)

uart.on("data",4, function(data)
if global_c~=nil then
global_c:send(data)
end
end, 0)
end