ESP8266 OTA from Internet

Hello. I use OTA (Over The Air) to upload programs to ESP8266. No problem from the local network, but now I am far away from my device (1 day trip), and I discovered a bug in my program, so I am trying to upload a program from internet, and getting crazy because it is not working.

I connect to the remote router through SSH, opening a tunnel:

ssh -L 9999:localhost:9999 remote_router

OK. Then I use SOCAT to pass UDP traffic over TCP tunnel .

socat  tcp4-listen:9999,reuseaddr,fork UDP:<ESP8266 IP>:8266

This is in remote_router, connected to ESP through WIFI and running openWRT. 8266 is OTA UDP port.

Then in my laptop (Linux), SOCAT again:

socat -T15 udp4-recvfrom:8266,reuseaddr,fork tcp:localhost:9999

Finally, I run in my laptop to upload a binary sketch.

./ -d -i --aut= -f ./sketch.bin

And it never connects, error “NO ANSWER”.

Trying to identify the problem I have created another UDP tunnel, but this time addressing port 53 (DNS Server) in router, and it is working, If I do

dig @ -p 8266

It gives me response. So, I don’t know why OTA UDP tunnel is not working.

Any idea?

OK. Finally SOLVED.

The problem was that OTA is using two channels. UDP 8266 for request, and then it connects to indicated TCP port in the request to upload the program.

So first we open a connection to the router linked with ESP8266, openning two tunnels, first one for UDP, second one for TCP:

ssh -L 39999:localhost:39999 -R *:39998:localhost:39998 remote_router

Then in router we redirect UDP OTA port to TCP Tunnel:

socat -d -d -T10 TCP4-LISTEN:39999,fork UDP4:<ESP8266 IP>:8266

Afterwards in laptop we redirect TPC to UDP again:

socat -d -d UDP4-LISTEN:8266,fork TCP4:localhost:39999

Finally in another terminal in laptop we upload the program with the next command:

./ -d  -i -p 8266 -I -P 39998 --auth='' -f ./sketch.bin

And the right result:

16:18:30 [INFO]: Sending invitation to:
('', 8266)
16:18:30 [INFO]: Waiting for device...
16:19:01 [INFO]: Waiting for result...
16:19:02 [INFO]: Result: OK
1 Like

Another option would be to use port forwarding in ESP router for UDP 8266 and in client router for a TCP port, but it is not a possibility in this case because ESP8266 router is behind NAT using a 3g dongle connection to internet.

In fact, I am using an intermediate server and ESP8266 router is initiating a SSH reverse connection to it, so I can SSH Back.

Hi liken
I am making a project that i need to upload a code to the nodemcu and i don’t have access to the same network as nodemcu can you help me with it? I don’t know that much in networking.