Chat freely about anything...

User avatar
By shimosaurus
#40778 Use Nodemcu firmware. Flash this file as init.lua:
Code: Select alltmr.alarm(1, 3*1000, tmr.ALARM_SINGLE, function()  --wait 3 seconds before run program to chance to reflash
    main()
end)   

function main()
    wifi.setmode(wifi.SOFTAP)
    uart.setup(0, 4800, 8, 0, 1, 0)

    print("Setting up server. Please connect to: " .. wifi.ap.getip())
    local connection = nil
    local srv = net.createServer(net.TCP, 300)
    srv:listen(9999, function(conn)
        if connection~=nil then
            connection:close()
            end
        connection = conn
        conn:on("receive",function(sck, pl)
            uart.write(0, pl)
            if string.find(pl, "quit")~=nil then
                connection:close()
                end
            end)
       
        conn:on("disconnection",function(conn)
                print("disconnection")
                connection=nil
                end)
    end)

    uart.on("data", "\r", function(data)
        print("receive from uart:", data)
        if string.find(data, "quit")~=nil then
            print("quit transmit mode")
            uart.on("data") -- unregister callback function
        elseif connection~=nil then
            connection:send(data)
            end
        end, 0)
    end

Connect to AP ESP_xxxx and read messages with netcat
Code: Select allnc 192.168.4.1 9999