Post your best Lua script examples here

User avatar
By alexhi
#7288
Code: Select all--!!!!nodemcu_512k_20150106
--Init.lua
PORT=7777 pin=3
gpio.mode(pin, gpio.INPUT)
tmr.alarm(1,5000, 1, function()
if wifi.ap.getip()~=nil  then
if gpio.read(pin)==1 then
tmr.stop(1) print("WIFI_UDP_RS232 V1.1 06.01.2015")
else
tmr.stop(1) print("Telnet V1.1") dofile("telnet.lua")
end end end)
uart.setup( 0,9600, 8, 0, 1, 0 )
srv=net.createServer(net.UDP)
srv:on("receive", function(srv, pl) tmr.wdclr() uart.write(0,pl) end)
srv:listen(PORT) uart.on("data",0,function(data)srv:send(data)end, 0)


if for 5sec close GPI0 then run telnet.
I like putty.

Code: Select all--telnet.lua
s=net.createServer(net.TCP,1000)
s:listen(23,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("Telnet V1.1")
end)


for test PC HERCULES Utility
for Android my app
https://play.google.com/store/apps/details?id=ru.shipov.termudp
Attachments
(799 Bytes) Downloaded 564 times
Last edited by alexhi on Wed Jan 21, 2015 12:36 am, edited 2 times in total.
User avatar
By fast62
#7815 Hello alexhi

Sorry my English


then Reset ESP

NodeMCU 0.9.5 build 20150118 powered by Lua 5.1.4
lua: init.lua:14: function arguments expected near ':'


I don't know were problem


Thank
User avatar
By alexhi
#7834
fast62 wrote:Hello alexhi

Sorry my English


then Reset ESP

NodeMCU 0.9.5 build 20150118 powered by Lua 5.1.4
lua: init.lua:14: function arguments expected near ':'


I don't know were problem


Thank

Hi
You should change the line to:
init.lua
srv:on("receive", function(srv, pl) tmr.wdclr() uart.write(0,pl) end)

and telnet.lua
c:on("receive",function(c,l)
c:on("disconnection",function(c)

Download the file udp.zip !!!
User avatar
By M0ebius
#8275 @alexhi:
I've tried your script and the udp send ("srv:send(data)") does not work here (NodeMCU 0.9.5 build 20150124)

To send a udp message a had to do:
Code: Select allc=net.createConnection(net.UDP, 0)
c:connect(8008,"192.168.4.255")
uart.on("data",0,function(data)c:send(data)end, 0)

Did i do something wrong, or is srv:send not working anymore?