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 my blog? Want to buy me coffee or beer?

LTC (litecoin): LeWzkcV2ArRv7Bi7TmrTpwkp6j2CZSLwfY

BTC (bitcoin): 1LzmUcwHK5Ys4zGPRoxYodjzpJsWiG61JY

DOGE (dogecoin): DQmS6EdDXssriDgSBpQMxYicHTiji6kMhx

ETH (ethereum): 0x387ff39c66e71c454ce5844c188c1a87835d2263

USDT (tether@ETH): 0xa69cae5a1da5ff5fb226e4bc87fe5d0f8c45908a

MANA (decentraland): 0xa69cae5a1da5ff5fb226e4bc87fe5d0f8c45908a

XMR (monero): 4JUdGzvrMFDWrUUwY3toJATSeNwjn54LkCnKBPRzDuhzi5vSepHfUckJNxRL2gjkNrSqtCoRUrEDAgRwsQvVCjZbRxBb8sEWJB1SCCuUEa