Platformio-core: Discover OTA-able esp8266/Arduino modules using dns-sd / mDNS

Created on 17 Jan 2016  Â·  6Comments  Â·  Source: platformio/platformio-core

To use OTA on the esp8266, we currently have to put something like upload_port=esp8266-c1ab73.local into platformio.ini.

More options:
http://docs.platformio.org/en/latest/platforms/espressif.html#platform-espressif-ota

This seems overly static to me. Wouldn't it be great if platformio would detect OTA-able devices just as seamless as it does auto-detect the serial port?

Turns out this would be pretty easy to implement using avahi (there are python bindings!)

# Look for suitable devices to upload to
avahi-browse -t -r  "_arduino._tcp"

# If there is only one device in the network you can just do:
IP=$(avahi-browse -t -v -r  "_arduino._tcp" 2>/dev/null | grep address | head -n 1 | cut -d "[" -f 2 | cut -d "]" -f 1)
echo $IP
echo "upload_port=$IP" >> platformio.ini

We could also check the TXT record to make sure it is the correct device model; and we could ask the user to select one from all available update-able devices on the network.

feature

Most helpful comment

On arduino ide whit esp core installed, the mDNS discovery is already present.
All OTAble esp is automatically listed under Ide upload port, but is always the user that must set manually the port, because if you have 10 esp in your house the system cannot auto-decide witch esp you want upload.
So i think that Platformio need only do the same arduino behaviour, by create an autodiscovery upload port presence, but not an auto-setting upload port.

This is thrue also for standard serial port, because you can have many esp connected to the same pc, so in the arduino ide you auto-found all available serial port, but after you must manually choose whitch ones you need use

All 6 comments

In general I like the idea - but I think its important to handle this different from the current serial implementation: Usually one or a few development devices are connected via serial and it's easy to make sure that the only the device(s) you want to flash is(are) connected.
But for OTA: There might be many different devices connected to the network with OTA enabled. How could PlatformIO decide automatically which one to use?

I would suggest to let the user decide by giving a prompt in the terminal.
Additional a commandline parameter to set the upload port/OTA device would be nice (Probably there is already one, haven't checked).

On arduino ide whit esp core installed, the mDNS discovery is already present.
All OTAble esp is automatically listed under Ide upload port, but is always the user that must set manually the port, because if you have 10 esp in your house the system cannot auto-decide witch esp you want upload.
So i think that Platformio need only do the same arduino behaviour, by create an autodiscovery upload port presence, but not an auto-setting upload port.

This is thrue also for standard serial port, because you can have many esp connected to the same pc, so in the arduino ide you auto-found all available serial port, but after you must manually choose whitch ones you need use

@Testato PlatformIO also allows to manually specify upload port as a serial device, media disk or IP/mDNS record. See

Yes, i know,
but there is no automatic Discovery like in the Official arduino Ide.
On Arduino IDE the port menu is automatic populated, so you do not must remember all your mcu name.

For example in your home you have 10 ESP with the OTA, every ESP have a unique mDNS name, so on arduino you receive automatically all 10 names in the list, and you will choose to witch upload.

Instead on Platformio you need remember exactly the name of all ESP that you have in your Home

Seeing as how platformio.ini should be revision controlled, I want to avoid putting a line in there that pertains only to my own personal development environment.

Will be reflected in PIO Home -> Devices soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0x587 picture 0x587  Â·  3Comments

r89m picture r89m  Â·  6Comments

Teo-CD picture Teo-CD  Â·  3Comments

HamzaHajeir picture HamzaHajeir  Â·  5Comments

malachib picture malachib  Â·  3Comments