Remote WebREPL interface with TURN (Traversal Using Relays around NAT)

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
alessio
Posts: 2
Joined: Thu Jul 07, 2022 8:03 pm

Remote WebREPL interface with TURN (Traversal Using Relays around NAT)

Post by alessio » Sun Jul 10, 2022 6:40 pm

I want to access my ESP32 console remotely and I think that the best way to do so is to create TCP tunnel from the ESP32 to a server and use this server as a really for the connections, so that when I connect using WebREPL client to the server, the connection is forwarded trough the TCP tunnel to the ESP32 board and here the request is then sent to the actual WebREPL server.

The code I come up with is available at https://gist.github.com/alessionossa/72 ... 0e4e71bc20, however the code on ESP32 gets stuck, probably because the current code requires too many parallel operations. I tried using both threads and uasyncio, but I was not able to get a working solution.

The structure is:
  • A server that listens on two ports:
    • First port is for the connection from the ESP32 board, this connection is persistent and the TCP tunnel will be used to forward traffic to the microcontroller.
    • Second port is for the external connection from WebREPL client.
  • The script on ESP32, which connects to the server creating a TCP tunnel and forwards the data coming from the tunnel to WebREPL's port.
Last edited by alessio on Mon Jul 11, 2022 5:12 pm, edited 1 time in total.

User avatar
jimmo
Posts: 2754
Joined: Tue Aug 08, 2017 1:57 am
Location: Sydney, Australia
Contact:

Re: TURN webrepl interface (Traversal Using Relays around NAT)

Post by jimmo » Mon Jul 11, 2022 1:15 am

alessio wrote:
Sun Jul 10, 2022 6:40 pm
The code I come up with is available at https://gist.github.com/alessionossa/72 ... 0e4e71bc20, however the code on ESP32 gets stuck, probably because the current code requires too many parallel operations. I tried using both threads and uasyncio, but I was not able to get a working solution.
What does "stuck" mean in this context? Can you Ctrl-C at the REPL?

alessio
Posts: 2
Joined: Thu Jul 07, 2022 8:03 pm

Re: TURN webrepl interface (Traversal Using Relays around NAT)

Post by alessio » Mon Jul 11, 2022 6:17 am

jimmo wrote:
Mon Jul 11, 2022 1:15 am
What does "stuck" mean in this context? Can you Ctrl-C at the REPL?
It blocks on

Code: Select all

WebREPL connection from: ('127.0.0.1', 51639)
but I can still Ctrl-C. If I do that I think it interrupts WebREPL code because I get

Code: Select all

Traceback (most recent call last):
  File "webrepl.py", line 43, in accept_conn
  File "websocket_helper.py", line 20, in server_handshake
KeyboardInterrupt: 
But also I get an unexpected log when it first connects to the server:

Code: Select all

[...]
Checkpoint 1: False; None; None
Connecting to ('159.223.29.36', 12014)...
Connected to ('159.223.29.36', 12014)
Checkpoint 2: True; <socket>; None
Connecting to ('localhost', 8266)...
Connected to ('localhost', 8266)
Checkpoint 3: True; <socket>; <socket>
Starting tasks...
Tasks started...
Tunnel daeomon sleeping
Checkpoint 4: True; <socket>; <socket>
Checkpoint 5: True; None; None
Checkpoint 1: False; None; None
[...]
The unexpected things are:
  • At Checkpoint 5 sockets variables are empty and actually it looks like it doesn’t wait

    Code: Select all

    await uasyncio.sleep(5)
    in this case (and only in this case);
  • It says

    Code: Select all

    Starting tasks...
    but it doesn’t print

    Code: Select all

    Started forwarding loop: remote -> localhost:8266
    Entered async_recvfrom(sock, count)
    Started forwarding loop: localhost:8266 -> remote
    Entered async_recvfrom(sock, count)

Post Reply