ESP resetter TCP version

First try

...based on Sorki's funky_bridge.lua

  • Configure wifi SSID and password
  • run script below
  • connect using nc ip.of.the.esp 1337
  • when you send "Buger say red led on" red led is turned on, simmilar for off
  • when you send "Buger say reset ESP" ESP will restart
  • other messages are forwarded to uart
  • data received on uart are sent to necat
redonmagic="Buger say red led on\n"
redoffmagic="Buger say red led off\n"
resetespmagic="Buger say reset ESP\n"

wifi.sta.connect()

--led pins
redpin=7
bluepin=6
gpio.write(redpin,gpio.HIGH)
gpio.mode(redpin,gpio.OUTPUT)
gpio.write(bluepin,gpio.LOW)
gpio.mode(bluepin,gpio.OUTPUT)

-- Create UART <-> TCP bridge
uartbridge = net.createServer(net.TCP, 180)
uartbridge:listen(1337, function(socket)
    local fifo = {}
    local fifo_drained = true
    local function sender(c)
        if #fifo > 0 then
            c:send(table.remove(fifo, 1))
        else
            fifo_drained = true
        end
    end
    local function s_output(str)
        table.insert(fifo, str)
        if socket ~= nil and fifo_drained then
            fifo_drained = false
            sender(socket)
        end
    end
    uart.on("data", s_output, 0)
    gpio.write(bluepin,gpio.HIGH)
    socket:on("receive", function(c, l)
    if (l == redonmagic) then
        gpio.write(redpin,gpio.LOW)
    elseif (l == redoffmagic) then
        gpio.write(redpin,gpio.HIGH)
    elseif (l == resetespmagic) then
        node.restart()      
    else
            uart.write(0, l)
    end
    end)
    socket:on("disconnection", function(c)
        uart.on("data")
    gpio.write(bluepin,gpio.LOW)
    end)
    socket:on("sent", sender)
end)

Links

Like this? - buy me a BEER using Bitcoin: 18zHcqpTydXAYuaYPh17H9nr3MybcqZJT1 - THANK YOU