Upload mit
init.lua
print('init.lua ver 1.2') wifi.setmode(wifi.STATION) print('set mode=STATION (mode='..wifi.getmode()..')') print('MAC: ',wifi.sta.getmac()) print('chip: ',node.chipid()) print('heap: ',node.heap()) -- wifi config start wifi.sta.config("SSID","PW") -- wifi config end --wenn alles getestet dofile hier aktivieren --dofile("main.lua")
main.lua
tmr.alarm(0, 1000, 1, function() if wifi.sta.getip() == nil then print("Connecting to AP...") else tmr.stop(0) print('IP: ',wifi.sta.getip()) --Telnet Server telnet_Server() end end) -- -- setup a telnet server that hooks the sockets input -- function telnet_Server() inUse = false function listenFun(sock) if inUse then sock:send("Already in use.\n") sock:close() return end inUse = true function s_output(str) if(sock ~=nil) then sock:send(str) end end node.output(s_output, 0) sock:on("receive",function(sock, input) node.input(input) end) sock:on("disconnection",function(sock) node.output(nil) inUse = false end) sock:send("Welcome to NodeMCU world.\n> ") end telnetServer = net.createServer(net.TCP, 180) telnetServer:listen(23, listenFun) end
per Telnet verbinden auf Port 23
uart.setup(0,9600,8,0,1,0) uart.write(0,string.char(0x1,0x2)) uart.on("data",0, function(data) print(data) end, 0)