I recently got esp8266 cheap wifi module. I had idea to use it with arduino and existing project that was using CmdMessenger library to comunicate over serial/usb port. After playing with esp8266 I found nice solution to how to replace serial cable. I installed NodeMCU on esp8266 and installed on it two scripts
1 2 3 4 5 6 7 8 |
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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
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 booting telnet server is opened on port 1001 and ip address is sent to arduino (“5,192.168.0.10;”) so that it can be printed on LCD. When connected from computer to esp8266 using python (terminal on 1001) i send for example uart.write(0,”1,255;”) and “1,255;” is sent to arduino and when arduino send something back to PC i send it like “print”123″” and 123 is printed on terminal/sent to python.