Data Sheet

34
Open the LuaLoader, set one serial port which connect the NodeMCU (“AP mode”) and
connecting , then click the “Upload File…” after connecting successful, choo se ESP 8266
NodeMCU ki t demo code -> P17_NodeMCU_Communication ->TCP Server-> init.lua. After
the upload completed then click “Download to download the init.lua file.
The following, set another serial port which connect the NodeMCU (“STA mode”) and
connecting , then click the “Upload File…” after connecting successful, choo se ESP 8266
NodeMCU ki t demo code -> P17_NodeMCU_Communication ->TCP Client-> init.lua. After
the upload completed then click “Download to download the init.lua file.
Demo code
AP:
print("ESP8266 Server")
wifi.setmode(wifi.STATIONAP);
wifi.ap.config({ssid="test",pwd="12345678"});
print("Server IP Address:",wifi.ap.getip())
sv = net.createServer(net.TCP)
sv:listen(80, function(conn)
conn:on("receive", function(conn, receivedData)
print("Received Data: " .. receivedData)
end)
conn:on("sent", function(conn)
collectgarbage()
end)
end)
STA:
print("ESP8266 Client")
wifi.sta.disconnect()
wifi.setmode(wifi.STATION)
wifi.sta.config("test","12345678") -- connecting to server
wifi.sta.connect()
print("Looking for a connection")
i=0
tmr.alarm(1, 2000, 1, function()
if(wifi.sta.getip()~=nil) then