Post your best Lua script examples here

User avatar
By Enrico Pastarini
#48936 Hi world, I have a little problem. I can not change baudrate from 115200 to 9600.
I have put into esp8266 latest version built from the NodeMCU build service. Here the link! http://nodemcu-build.com/
When I turn on esp I can see on serial monitor:

NodeMCU custom build by frightanic.com
branch: master
commit: cdaf6344457ae427d8c06ac28a645047f9e0f588
SSL: false
modules: file,gpio,net,node,tmr,uart,wifi
build built on: 2016-06-07 08:43
powered by Lua 5.1.4 on SDK 1.5.1(e67da894)
lua: cannot open init.lua

After this i can put my firmware into esp8266. But I can not change baudrate!
This is my code:

nameSP= "PROVA"
pswSP = "12345678"
count=0
pin=0
connected = false

wifi.setmode(wifi.SOFTAP)
wifi.ap.config({ssid= nameSP ,pwd= pswSP})

gpio.mode(pin, gpio.OUTPUT)
gpio.write(pin, gpio.HIGH)

sv=net.createServer(net.TCP, 600)
global_c = nil

sv:listen(9999, function(c)

c:on("disconnection", function()
connected = false
end)

connected = true
if global_c~=nil then
global_c:close()
end
global_c=c
c:on("receive",function(sck,pl) uart.write(0,pl) end)
end)

uart.on("data","\n", function(data)
if global_c~=nil then
global_c:send(data)
end
end, 0)

If I add this below:
uart.setup(0, 9600, 8, uart.PARITY_NONE, uart.STOPBITS_1, 0)
all does not works; i reach the timeout of esp8266

Somebody can halp me?
If nobody can halp me, can someone tell me where i can foud a tcp server bridge to uart?
Thanks
Enrico