Page 1 of 1

esp32s2 flash remotely, socat

Posted: Wed Dec 06, 2023 6:55 am
by whoim2
Hello!
I'm trying to forward the ESP serial port for remote firmware.
ESP is connected to the Windows machine and the flashing port is com41, the port in normal mode (usb>serial) is com43. First I try the normal mode.
On this computer I start a connection to the Linux server:
socat /dev/ttyS42,raw,echo=0 TCP:serverip:1723 (com43 to remote)

The server is running: socat -d -d -d PTY,link=/dev/ttyS10,raw,echo=0 tcp-listen:1723 (remote to virtual ttyS10)

I uploaded a sketch to ESP that outputs the test line to the serial and it works on the server: cat /dev/ttyS10 shows the lines "test" from esp. Everything is working.

However, when I put the ESP into download mode and try to connect com41 for flashing remotelly:
socat -d -d -d /dev/ttyS40,raw,echo=0 TCP:serverip:1723

I get instantly:
2023/12/06 06:45:23 socat[4324] I interpreting address "/dev/ttyS40" as file name
2023/12/06 06:45:23 socat[4324] I setting option "raw"
2023/12/06 06:45:23 socat[4324] I setting option "echo" to 0
2023/12/06 06:45:23 socat[4324] I "/dev/ttyS40" is not a socket, open()'ing it
2023/12/06 06:45:23 socat[4324] N opening character device "/dev/ttyS40" for reading and writing
2023/12/06 06:45:23 socat[4324] I open("/dev/ttyS40", 012, 0666) -> 3
2023/12/06 06:45:23 socat[4324] W cannot query current terminal settings on fd 3: Invalid argument
2023/12/06 06:45:23 socat[4324] E tcgetattr(3, 0x28a844): Invalid argument
2023/12/06 06:45:23 socat[4324] N exit(1)

What's wrong?

Re: esp32s2 flash remotely, socat

Posted: Wed Dec 06, 2023 7:23 am
by ESP_Sprite
Not sure why that doesn't work, but you may want to look at the functionality esptool has natively for this: see the comments here.

Re: esp32s2 flash remotely, socat

Posted: Wed Dec 06, 2023 10:39 am
by whoim2
ESP_Sprite wrote:
Wed Dec 06, 2023 7:23 am
Not sure why that doesn't work, but you may want to look at the functionality esptool has natively for this: see the comments here.
thanks, im using socat on windows side:

Code: Select all

socat -d /dev/ttyS%COM-1% tcp:serverrip:port1
and socat on server side:

Code: Select all

socat -d TCP4-LISTEN:port1,reuseaddr TCP4-LISTEN:port2,reuseaddr,fork,bind=127.0.0.1
and flashing:

Code: Select all

esptool.py --chip esp32s2 --port socket://127.0.0.1:port2 write_flash ...
works perfectly!

Re: esp32s2 flash remotely, socat

Posted: Wed Dec 06, 2023 11:29 am
by ESP_krzychb
Great news you made it working!

For anybody exploring this topic, please refer to Esptool.py Documentation > Remote Serial Ports

Re: esp32s2 flash remotely, socat

Posted: Wed Dec 06, 2023 10:31 pm
by whoim2
ESP_krzychb wrote:
Wed Dec 06, 2023 11:29 am
Great news you made it working!

For anybody exploring this topic, please refer to Esptool.py Documentation > Remote Serial Ports
I read this page, it was very helpful, thank you! The only thing I don’t like is that sometimes the firmware is only installed on the second attempt, as I noticed, after a reset with entering the bootloader. The esptool closes after the esp reset > enter bootloader and something like that. But I did the firmware via the website and PHP, so there may be some glitches there)