Set network port for upload?

so i had been using jeelabs esp-link on an esp8266 to flash arduinos with arduino ide. after setting ‘arduino’ as the mDNS server name on the esp, it shows up in arduino IDE as an available upload port. for a variety of reasons i recently switched to VS Code with the platformio extension and i cant figure out how to emulate this here. i dont have any experience using avrdude directly and minimal experience with platformio at this point but i believe that i have to add some flags to the platformio.ini file? somthing about port 23?

If I read that doc correctly then avrdude just has to be given the upload port flag -P "net:esp-link:23", where esp-link is the hostname of the network device and 23 is the port.

The upload port is controllable with upload_port in the platformio.ini.

I’ve tried this with the platformio.ini

platform = atmelavr
board = uno
framework = arduino
upload_port = net:arduino:23

and, looking at the “Verbose Upload” log, this does the correct invocation

Use manually specified: net:arduino:23
avrdude -v -p atmega328p -C C:\Users\Max\.platformio\packages\tool-avrdude\avrdude.conf -c arduino -b 115200 -D -P "net:arduino:23" -U flash:w:.pio\build\uno\firmware.hex:i

avrdude: Version 6.3, compiled on Sep 12 2016 at 17:24:16
         Copyright (c) 2000-2005 Brian Dean,
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Max\.platformio\packages\tool-avrdude\avrdude.conf"

         Using Port                    : net:arduino:23
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: net_open(): unknown host "arduino"

avrdude done.  Thank you.

So of course in my network there’s no mDNS host arduino available and fails, but avrdude gets the right info and tries to connect to it, so it should work in your setup. If the hostname thing fails, try replacing arduino with the direct IP address.

yes! that still failed but it definitely tried! i saw the esp blink when i clicked upload so i think the issue is with my wiring, ill play with it again in the morning. thank you!!

I’ve tried

platform = atmelavr
board = megaatmega2560
framework = arduino
monitor_speed = 115200
upload_port = net:

but in the Terminal-Window I get:

Building .pio\build\megaatmega2560\firmware.hex
Configuring upload protocol...
CURRENT: upload_protocol = wiring
Looking for upload port...
Using manually specified: net:
Uploading .pio\build\megaatmega2560\firmware.hex
avrdude: ser_drain(): read error: Falscher Parameter.

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout

Where can I see that detailed output with the commandline and so?
As a try I uploaded (over com port) a program which is just doing some serial prints and those I can see in a Telnet client but upload fails.
can anyone help me further?
PS: “Falscher Parameter” = “wrong parameter”

Try setting upload_protocol = arduino too, in your platformio.ini.

the output chenges to:

Building .pio\build\megaatmega2560\firmware.hex
Configuring upload protocol...
AVAILABLE: arduino
CURRENT: upload_protocol = arduino
Looking for upload port...
Using manually specified: net:
Uploading .pio\build\megaatmega2560\firmware.hex
avrdude: ser_drain(): read error: Falscher Parameter.

avrdude: ser_drain(): read error: Falscher Parameter.

avrdude: ser_drain(): read error: Falscher Parameter.

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x30
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x20
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x30

Indeed I get the same errors. I setup my Arduino Mega2560 and NodeMCU and I cannot get it to flash via avrdude and net:...

The avrdude: ser_drain(): read error seem to be specific to the older avrdude 6.3 version though, these are not present when selecting the 7.x package (platform_packages = tool-avrdude@~1.70100.0). Nonetheless, neither can flash.

What does work however is via the Web API that is referenced in their megaflash script.

>curl -m 10 -v -s  -XPOST "" && curl -m 20 -v -s -g -d "@C:/Users/Max/temp/net/.pio/build/megaatmega2560/firmware.hex" "
Success. 1536 bytes at 115200 baud in 1.8s, 829B/s 7% efficient

This does prove that my wiring is correct, which is btw

  • NodeMCU “RX” ↔ “TX0” of Mega2560
  • NodeMCU “TX” ↔ “RX0” of Mega2560
  • NodeMCU GPIO12 (=“D6”) ↔ “RESET” of Mega2560

But maybe avrdude has weird timing issues with resetting the bootloader just in time.

In any case, I recon it’s possible to make PlatformIO use the upload via HTTP, using a small extra_script. Let’s see how that goes…

Thanks in advance for the help

Check out

A picture is worth a thousand words?

I’ve commited 11f714db against that, please pull the newest version again.

Status with your change:

Configuring upload protocol...
CURRENT: upload_protocol = wiring
Looking for upload port...
Using manually specified:
Uploading .pio\build\megaatmega2560\firmware.hex
Uploading to
Trying to reset board.
Warning: Retrying to sync to Optiboot.
<last 2 lines repeating 4 times>
Uploading firmware .pio\build\megaatmega2560\firmware.hex
Not Found.

Trying to reset board.
Uploading firmware .pio\build\megaatmega2560\firmware.hex
Not Found.
<last 3 lines repeating 3 times>

Trying to reset board.
Exhausted retries for uploading.
*** [upload] Error 4294967295

I checked the serial communication in both directions via the microcontroller console.
To test the reset, I plugged the green wire into the other GND of the NodeMCU and saw a restart.
But I constantly measure 3.3V from the D6 (the reset pin is on GPIO12 see screenshot), even during an upload. Since I suspected my measuring device (Fluke 75 III) was too slow, I connected an LED. You should at least see a flickering or is the pulse at 0V so short that you can’t notice it? According to my observation, the LED was lit continuously and unfortunately I don’t have an Oscar.

and unfortunately I wasn’t allowed to send the wiring in one post… “Error: New users are only allowed to send one embedded media per post”

Did you try with the direct IP?

No, but I found the worm.
On the esp-link download page I learned about the alpha version through its announcement
“Warning: some users have trouble getting this release to work. After flashing nothing happens. Please use 3.0.14 instead for now.” I was put off and went straight to 3.0.14…
If I had read a little bit further… under version 3.2.7 alpha it said:
New in 3.2 over 2.x
- support to program ATmega2560
Well, no stable version will help if my project is not yet supported.
I would like to thank you for your professional support and wish everyone patience while reading.It works !

Can I ask for your help again?
It works wonderfully with a separate nodemcu and mega.
But there are still problems with the mega + esp8266 board. I think if the esp8266 gives a reset to the Mega via gpio12, the esp8266 is reset at the same time. He is sawing on the branch he is sitting on. In any case, there is a dropout in the ping and existing Telnet connections break down. Luckily the WiFi connection is back up faster than the Mega returns. But with
r ="http://" + host + "/pgmmega/sync", timeout=10)
There is a bang in
As a test, I made an output print("done pgmmega sync") behind it. But it doesn’t come. Instead this:

Trying to reset board!
Traceback (most recent call last):
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\urllib3\", line 449, in _make_request
     six.raise_from(e, None)
   File "<string>", line 3, in raise_from
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\urllib3\", line 444, in _make_request
     httplib_response = conn.getresponse()
   File "C:\Users\Ingo\.platformio\python3\lib\http\", line 1377, in getresponse
   File "C:\Users\Ingo\.platformio\python3\lib\http\", line 320, in begin
     version, status, reason = self._read_status()
   File "C:\Users\Ingo\.platformio\python3\lib\http\", line 281, in _read_status
     line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
   File "C:\Users\Ingo\.platformio\python3\lib\", line 704, in readinto
     return self._sock.recv_into(b)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\requests\", line 489, in send
     resp = conn.urlopen(
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\urllib3\", line 787, in urlopen
     retries = retries.increment(
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\urllib3\util\", line 550, in increment
     raise six.reraise(type(error), error, _stacktrace)
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\urllib3\packages\", line 770, in reraise
     raise value
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\urllib3\", line 703, in urlopen
     httplib_response = self._make_request(
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\urllib3\", line 451, in _make_request
     self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\urllib3\", line 340, in _raise_timeout
     raise ReadTimeoutError(
urllib3.exceptions.ReadTimeoutError: HTTPConnectionPool(host='', port=80): Read timed out. (read timeout=10)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
   File "C:\Users\Ingo\Documents\PlatformIO\Projects\pio-esp-link-mega2560-main\pio-esp-link-mega2560-main\", line 72, in <module>
   File "C:\Users\Ingo\Documents\PlatformIO\Projects\pio-esp-link-mega2560-main\pio-esp-link-mega2560-main\", line 68, in main
     ok = upload(args.port, args.file[0])
   File "C:\Users\Ingo\Documents\PlatformIO\Projects\pio-esp-link-mega2560-main\pio-esp-link-mega2560-main\", line 37, in upload
     if not reset_to_sync(host):
   File "C:\Users\Ingo\Documents\PlatformIO\Projects\pio-esp-link-mega2560-main\pio-esp-link-mega2560-main\", line 8, in reset_to_sync
     r ="http://" + host + "/pgmmega/sync", timeout=10)
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\requests\", line 115, in post
     return request("post", url, data=data, json=json, **kwargs)
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\requests\", line 59, in request
     return session.request(method=method, url=url, **kwargs)
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\requests\", line 587, in request
     resp = self.send(prep, **send_kwargs)
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\requests\", line 701, in send
     r = adapter.send(request, **kwargs)
   File "C:\Users\Ingo\.platformio\penv\lib\site-packages\requests\", line 578, in send
     raise ReadTimeout(e, request=request)
requests.exceptions.ReadTimeout: HTTPConnectionPool(host='', port=80): Read timed out. (read timeout=10)
*** [upload] Error 1

Do you think this can be eliminated or circumvented?

Are you testing this on custom hardware? The ESP8266’s RESET and Mega2560’s reset must be separate, otherwise this is indeed resetting itself via the GPIO pin.

I’m testing this board

(Switches 1 and 2 are of course ON for the upload and a cable from esp2866 gpio12 to reset at the bottom left of the 3rd connection)

If the schematic found here is correct, then that’s impossible. The ESP8266’s “EXT_RSTB” signal couples via a diode (D3) into “RESET” which is also the Mega2560’s reset signal. You would have to find and desolder D3 to make this work.

You should be able to find the D3 diode with a multimeter since it would be directly connected to the RESET pin (on the header) on one side, the other side going to the the ESP8266.

Hm there seem to be different schematics available, e.g. here. In that schematic, that would diode D4.

1 Like