Chat freely about anything...

User avatar
By Liken
#83807 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:
Code: Select allssh -L 9999:localhost:9999 remote_router


OK. Then I use SOCAT to pass UDP traffic over TCP tunnel .
Code: Select allsocat  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:

Code: Select allsocat -T15 udp4-recvfrom:8266,reuseaddr,fork tcp:localhost:9999


Finally, I run espota.py in my laptop to upload a binary sketch.
Code: Select all./espota.py -d -i 127.0.0.1 --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
Code: Select alldig @127.0.0.1 -p 8266 google.com


It gives me response.

So, I don't know why OTA UDP tunnel is not working.
User avatar
By Liken
#83820 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:
Code: Select allssh -L 39999:localhost:39999 -R *:39998:localhost:39998 remote_router


Then in router we redirect UDP OTA port to TCP Tunnel:
Code: Select allsocat -d -d -T10 TCP4-LISTEN:39999,fork UDP4:<ESP8266 IP>:8266


Afterwards in laptop we redirect TPC to UDP again:
Code: Select allsocat -d -d UDP4-LISTEN:8266,fork TCP4:localhost:39999

Finally in another terminal in laptop we upload the program with the next command:
Code: Select all./espota.py -d  -i 127.0.0.1 -p 8266 -I 0.0.0.0 -P 39998 --auth='' -f ./sketch.bin

And the right result:
Code: Select all16:18:30 [INFO]: Sending invitation to: 127.0.0.1
('127.0.0.1', 8266)
16:18:30 [INFO]: Waiting for device...
Uploading.............................................................................................................................................................................................................................................................................................
16:19:01 [INFO]: Waiting for result...
16:19:02 [INFO]: Result: OK
User avatar
By Liken
#83821 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, so I can SSH Back.