How to connect the console to a socket

owenjames
Posts: 12
Joined: Fri Sep 02, 2022 6:24 pm

How to connect the console to a socket

Postby owenjames » Sat Oct 21, 2023 8:42 am

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?

username
Posts: 541
Joined: Thu May 03, 2018 1:18 pm

Re: How to connect the console to a socket

Postby username » Sun Oct 22, 2023 4:27 am

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
Attachments
myTelnet_10_21_2023_232606.zip
(1.65 KiB) Downloaded 592 times

owenjames
Posts: 12
Joined: Fri Sep 02, 2022 6:24 pm

Re: How to connect the console to a socket

Postby owenjames » Sat Nov 25, 2023 8:43 am

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.

DrMickeyLauer
Posts: 168
Joined: Sun May 22, 2022 2:42 pm

Re: How to connect the console to a socket

Postby DrMickeyLauer » Sat Mar 23, 2024 1:05 pm

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?

Who is online

Users browsing this forum: Google [Bot] and 55 guests