Page 1 of 1

How to connect the console to a socket

Posted: Sat Oct 21, 2023 8:42 am
by owenjames
I am using the Console component for a serial command interface but want to also access it remotely. It seems the Console is hard-wired to UART i/o, is it possible to connect it to a network socket?

Re: How to connect the console to a socket

Posted: Sun Oct 22, 2023 4:27 am
by username
I am using the Console component for a serial command interface but want to also access it remotely. It seems the Console is hard-wired to UART i/o, is it possible to connect it to a network socket?
Yes. A while ago I wanted the same thing. So I created a TCP socket server on port 23 (telnet port)

Basically, whenever I want to print to that socket in my app. I just use: printft("Hello World\r\n");
Attached are the files for that. However, it's for my app and you'll have to figure out the things that are hard coded in like
CONFIG_TELNET_PORT_NUMBER, which is defined as 23, and the header files that are needed.

You will also need this part to get it going.

Code: Select all

        #ifdef CONFIG_TELNET_ENABLED

            // Start telnet service for printf's
            xTaskCreatePinnedToCore(
            TaskTelnet,                           // Task function.
            "TaskTelnet",                         // name of task.
            8192,                                 // Stack size of task
            NULL,                                 // parameter of the task
            CONFIG_TELNET_PRIORITY,               // priority of the task
            &xTaskHandleList[xtaskListCounter++], // Task handle to keep track of created task
            TELNET_CPU_CORE);

        #endif // CONFIG_TELNET_ENABLED

Re: How to connect the console to a socket

Posted: Sat Nov 25, 2023 8:43 am
by owenjames
So now I have a Console REPL session connected to a telnet session by reassigning stdin and stdout to the telnet socket. But problems remain. Foremost is not being able to detect when the connection is closed remotely. REPL blocks on line input and does not detect it. I tried recv(MSG_PEEK) in the socket thread which succeeds in detecting remote close, but corrupts the REPL stdin read, presumably because there are 2 threads asynchronously accessing the stream. I think a esp_console_new_repl_socket() is required, similar to esp_console_new_repl_uart() but with support to detect remote close and appropriate settings for socket io.

Re: How to connect the console to a socket

Posted: Sat Mar 23, 2024 1:05 pm
by DrMickeyLauer
Did you pursue this any further? I'm going to look into this soon, since I absolutely want this feature working for me.

Can you share what you did already?