0

I'm using and ESP8266 with Nodemcu to communicate with a serial terminal using Putty. Using escape sequences like referenced in these questions:

Read ANSI escape from terminal

How do I determine size of ANSI terminal?

List of escape sequences https://vt100.net/docs/vt100-ug/chapter3.html

I am trying to read back an escape sequence that is a reply to find the cursor position using LUA. I don't seem to be getting a visible reply (expected), but I also don't seem to get anything. Everything except the reply seems to work.

What am I doing wrong, how can I capture the response?

  -- Clear screen
  uart.write(0, "\033[2J")

  -- Setup event handler callback to read data from terminal
  -- Control sequence is terminated with an 'R'
  -- I'm replacing ESC in the reply so that I can hopefully get a visible reply like _[25;80R

  uart.on("data", 0, function(data)
    if data ~= 'R' then
      uart.write(0, data)
    end
    if data == '\033' then
      uart.write(0, "_")
    end
  end, 0)

  -- ESC = \033
  
  -- cursorpos(v,h) CUP    Move cursor to screen location v,h     ^[[<v>;<h>H
  uart.write(0, "\033[20;20H")
  
  uart.write(0, "\033[6n")

  -- Response:
  -- cursorpos CPR         Response: cursor is at v,h          ^[<v>;<h>R
Biyau
  • 121
  • 1
  • 12

1 Answers1

0

Looks like I had a syntax error with my uart read handler. I changed the /033 for ESC to CTRL-v[ and the condition for my IF statement. I'm not sure why the \033 didn't work.

For testing, I also changed the 20;20 part to 200;200 just to see how that worked and it gave the correct expected response: _[45;157R

I changed the code from:

  uart.on("data", 0, function(data)
    if data ~= 'R' then
      uart.write(0, data)
    end
    if data == '\033' then
      uart.write(0, "_")
    end
  end, 0)

To:

 uart.on("data", 0, function(data)
 if data == '\27' then 
   uart.write(0,"_")
 else
   uart.write(0, data) end end, 0)
Biyau
  • 121
  • 1
  • 12