PlatformIO Community

ESP32 OTA (via ethernet) doesn't want to work

Trying to add OTA to an ESP-based project. Network uploading via Arduino IDE works fine, PIO IDE gives a warning and successfully compiles without uploading. Removing the upload_protocol = espota from the platformio.ini allows it to attempt an upload, but it fails to get a reply from the device, as PIO seems be using a random port

The upload_protocol = espota syntax is correct.

What version of the platformio espressif8266 framework are you running? espota was only introduced as an option in 2.1.0 (current version is 2.2.1).

I doubt the port selection is platformio’s doing - as it merely uses the espota tool provided with the Arduino ESP8266 core…

Thanks for the quick reply!

Turns it it’s supposed to choose a random port, and forcing it to a port still doesn’t work.

I’m actually using an ESP32 board, using the Espressif 32 (1.8.0) platform via the Arduino framework.

1 Like

Derp… well, um, the docs indicate the syntax is valid there also… although I can’t see where support was actually added… oh, it was there out of the box… fair enough.

So, if you’re getting a

Sending invitation to myesp32.local ..........
11:00:14 [ERROR]: No response from the ESP

or a

Sending invitation to 192.168.0.100 ..........
11:04:00 [ERROR]: No response from the ESP

for me at least… adding the port does fix it. I checked the Arduino IDE espressif32 BSP upload syntax, and they do specify it … i.e.

Arduino IDE

C:\Users\Peter\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.2/tools/espota.exe -i 192.168.0.100 -p 3232 --auth= -f C:\Users\Peter\AppData\Local\Temp\arduino_build_302100/sketch_jun27a.ino.bin 

vs PlatformIO

"C:\platformio\stable\scripts\python.exe" "C:\Users\Peter\.platformio\packages\framework-arduinoespressif32\tools\espota.py" --debug --progress -i 192.168.0.100 -f .pioenvs\esp32dev-OTA\firmware.bin

This is what worked for me (with the example OTA sketch and ArduinoOTA.setHostname("myesp32");)

[env:esp32dev-OTA]
platform = espressif32
board = mhetesp32minikit
framework = arduino
upload_protocol = espota
upload_port = "myesp32.local"
upload_flags = -p 3232

Some reason, it still give the unknown protocol error when using the espressif32 platform, though setting the platform to https://github.com/platformio/platform-espressif32.git#feature/stage seems to fix that issue.

To make sure I’m not going crazy, I tried out the code on an ESP8266 (via wifi) and that worked fine. Additionally, it seems to work on the ESP32 via wifi.

However, changing it to ethernet seems to cause some issues. It does seem to be connecting to the device, though the device doesn’t respond correctly.
Logs from computer:

20:00:41 [INFO]: Waiting for device...
20:00:51 [ERROR]: No response from device
*** [upload] Error 1

Logs from the device:

Start updating sketch
Progress: 0%
[E][Updater.cpp:258] end(): premature end: res:0, pos:0/787040
Error[4]: End Failed

Also, the mDNS doesn’t seem to use the custom name, and defaults to esp32-[MAC].local which I guess I can live with…

Updating it via Arduino IDE via network port does process the OTA update properly :confused:

Interesting… because as you can see… I’m using the espressif32 platform (standard, not via git) as well, with a Wemos D1 Mini form-factor ESP32, and it worked just fine here…

How are you setting the mDNS name? Is it via ArduinoOTA.setHostname(); or through via MDNS.begin(); As I havn’t tried the latter form with OTA…

Is this a custom board, or something off the shelf? Just wondering how it has Ethernet capability…

I was using the wESP32 board earlier, though that one might have fried. Currently I’m working with an Olimex ESP32-EVB

I used MDNS.begin(); though ArduinoOTA.setHostname(); before ArduinoOTA.begin() does seem to work!
Also, doing all the ArduinoOTA stuff before the mDNS stuff (and MDNS.begin('name')) works too

Ah, that makes sense now (Olimex ESP32-EVB) … I remember seeing those boards and going ‘huh?’ when trying to work out why bother with Ethernet when you’ve got perfectly good WiFi :wink:

Curiser and curioser… maybe you’ve found a bug in the ESP32 core! :laughing: Real test would be to set one name with ArduinoOTA, and another with mDNS… and see which one takes… does the later call properly overide the other… I suspect if you start ArduinoOTA before mDNS, that’s the problem… because (on the ESP8266 core, at least) mDNS is started internally in the library… so it’s probably already begun if you call mDNS.begin() after starting that…

Anyway… sounds like you’re making progress! :smiley:

Just an addendum… had a look at the ESP32 source… and I can see where mDNS is initialised… so if you’re not using mDNS for something else, ArduinoOTA does it all itself… You might be about to use ArduinoOTA.setMdnsEnabled(false); to take it over entirely yourself… but should also probably then add MDNS.enableArduino() if you want OTA to still work.

Mostly got that board because of all the different things they smashed into the board (and at a reasonable price) It makes prototyping a bit cleaner. :smiley:

The main project I’m working on is going to be needing a good 40 or so devices, and ethernet tends to be faster, more reliable, and POE is a nice bonus to help reduce wiring.

Nevertheless, using the Ethernet connection, the OTA update works when using the Arduino IDE, but fails when using the PlatformIO IDE. Any idea what might cause this?

1 Like

Well, PoE… that says it all! :smiley: Yeah, it does look like a nice board for those don’t-know-exactly-what-this-project-will-need-yet projects…

There’s just been an update to the ESP32 platform, so make sure you run pio update from the VSCode terminal to get that… one of the changes in in relation to espota… so it could be the fix you need.

So this is ethernet only, the WiFi is turned off? Since I don’t have a ethernet board, I can’t reproduce to test this any further… so about all I can suggest is if the Arduino IDE can see it… it should work with platformIO also… then again, it seem the change in the 1.9.0 espress32platform is in relation to using the version of espota included with the platform… so there is a change they weren’t’ the same version, so had slightly different behaviours. Other than that, about about addressing the device by IP instead of via hostname… does it upload with platform IO then?

Technically it is connecting to the device and initializing the OTA update, but the device serial gets stuck on 0%, PIO says Waiting for device.. then No response from device and the device says [E][Updater.cpp:258] end(): premature end: res:0, pos:0/796960 likely from a timeout.

On another note, it now likes espota via platform = espressif32 so no more need for the Stage :smiley:

Nice… one step forward at least. Well… :raspberry: …

Have you tried doing a verbose upload so you can get the command line pio is using for the upload, and adding -p 3232 to it? Just wondering if it’s the absense of that playing some part (currently updating espressif32 myself, so I could be removing :foot: from :open_mouth: momentarily…

Yep, got the -p 3232. Without that, it defaults to port 8266, oddly enough, and doesn’t even make the connection.

upload command:
"c:\users\peter\.platformio\penv\scripts\python.exe" "C:\Users\Peter\.platformio\packages\framework-arduinoespressif32\tools\espota.py" "-p 3232" --debug --progress -i olimex-evb-demo.local -f .pioenvs\esp32-evb\firmware.bin

Well, that’s actually my upload command… from espressif32 @ 1.8.0, but yeah, I see what you mean now…

So, it looks like on the ESP32, there is a bug in the OTA upload - because the espota tool used in the esp32 arduino core is either an exact copy or a tweaked version of the one used on the ESP8266, it still references the ESP8266 everywhere, including the port it defaults to. Hence the need for the -p 3232… which is missing in PIO… I’ll either do up an issue for that, or a PR if I can find the relevant line…

Anyway (I’m on my linux install atm, so slightly different config)… On WiFi, I get this now…

"/opt/platformio/stable/bin/python2" "/home/pfeerick/.platformio/packages/framework-arduinoespressif32/tools/espota.py" "-p 3232" --debug --progress -i "myesp32.local" -f .pioenvs/mhetesp32minikit-OTA/firmware.bin
11:38:28 [DEBUG]: Options: {'timeout': 10, 'esp_ip': 'myesp32.local', 'host_port': 56368, 'image': '.pioenvs/mhetesp32minikit-OTA/firmware.bin', 'host_ip': '0.0.0.0', 'auth': '', 'esp_port': 3232, 'spiffs': False, 'debug': True, 'progress': True}
11:38:28 [INFO]: Starting on 0.0.0.0:56368
11:38:28 [INFO]: Upload size: 751232
Sending invitation to myesp32.local
11:38:29 [INFO]: Waiting for device...
Uploading: [============================================================] 100% Done...

11:38:42 [INFO]: Waiting for result...
11:38:43 [INFO]: Result: OK
11:38:43 [INFO]: Success

How long does it take before it ‘times out’? The default is 10… but I don’t know if that’s 10 seconds… Maybe override that also with -t 20 and see if it’s just a slow, problem child? :smiley:

It seems to make the connection in ~5 sec, and the timeout is about 10 sec. Adding -t 60 doesn’t appear to change how long it waits before espota gives up. Changing it to -t 0 causes the device to continuously loop as if it’s getting attempt after attempt, even though espota isn’t running anymore and never actually made the connection :confused:

Ouch! :open_mouth:

That’s about all I can offer up… other than generic ‘have you tried with the firewall and anti-virus tempoarily turned off / paused’…

@maxgerhardt Do you know anything about OTA / espota.py and ESP32s over Ethernet? - Derp… solved now.

Stupid windows firewall…
My Ethernet network was set to the Public Network settings :laughing:

It works now :rofl:

He he… funny you mention that… I got stung with exactly the same thing just recently… I half wonder if either the latest or the previous Windows feature update stuffed it up on me… it should’ve been set to private network… :-/

Anyhoo… at least that’s one problem down… only 99,999 more to solve! :smiley: :smiley: Have fun! :smiley:

1 Like