I am starting a project using two ESP8266-01 to transfer data via WiFi between 2 Arduinos. I know that this is not ideal, but I have to do it. The prblem is: after a week of googling, I am still having trouble programming in Lua, and my codes won't work. If you could just take a look at them and let me know what I'm doing wrong or point me in the right direction, I would appreciate it.
ESP CLIENT
wifi.sta.disconnect()
wifi.setmode(wifi.STATION)
wifi.sta.config("test","12345678") -- connecting to server
wifi.sta.connect()
uart.setup(0,9600,8,0,1,1)
tmr.alarm(1, 2000, 1, function()
if(wifi.sta.getip()~=nil) then
tmr.stop(1)
cl=net.createConnection(net.TCP, 0)
cl:connect(80,"192.168.4.1")
uart.on("data", "}", --the string ends on }
function(data)
tmr.alarm(2, 5000, 1, function()
cl:send(data)
end)
end, 0)
end
end)
ESP SERVER
wifi.setmode(wifi.STATIONAP);
wifi.ap.config({ssid="test",pwd="12345678"});
sv = net.createServer(net.TCP)
uart.setup(0, 9600, 8, uart.PARITY_NONE, uart.STOPBITS_1)-- setup UART1 i.e. pin GPIO2
sv:listen(80, function(conn)
conn:on("receive", function(conn, receivedData) --data received
print(receivedData)
uart.write(0, receivedData)
end)
conn:on("sent", function(conn)
collectgarbage()
end)
end)
tmr.delay(1000000)
P.S. I already checked and Client reads the serial from the first Arduino perfectly. So the problem is in the communication between the 2 ESPs.