I had existing Arduino project that was using CmdMessenger library. I wanted to replace cable with esp8266 and after some playing I found easiest way to do it. I installed NodeMCU on esp8266 and installed on it two scripts
init.lua
wifi.setmode(wifi.STATION)
wifi.sta.config("ssid","password")
dofile("tel.lua")
tmr.alarm(0, 5000, 0, function()
uart.write(0,"\n\r5,")
uart.write(0,wifi.sta.getip())
uart.write(0,";")
end )
and tel.lua
s=net.createServer(net.TCP,180)
s:listen(1001,function(c)
function s_output(str)
if(c~=nil)
then c:send(str)
end
end
node.output(s_output, 0)
c:on("receive",function(c,l)
node.input(l)
end)
c:on("disconnection",function(c)
node.output(nil)
end)
print("Connected\r\n")
end)
when esp8266 boots it connects to my router and sends it's IP to Arduino ("5,192.168.0.10;") IP is printed on LCD (although it's fixed on router by mac address) When connected from PC I send for example uart.write(0,"1,255;) and Arduino receives it. When sending data back to PC from arduino I send "print"123"" (with print and quotes) and python script receives 123. I was looking for some easy solution and could not find it (there is transparent serial mode but I don't think it works in STA mode and telnet server or I just could not make it work) Anyway it works for me and I hope someone will find it useful.