PlatformIO Community

Pack binaries for distribution

Hello !

Thanks for platformio, it makes development of Arduino-like based projects a bit more professional and much easier.

I’m using platformio to handle the firmware part of a project that includes an Arduino communicating with a computer program. The program is in Python and managed with Poetry. Not that it really matters, but for the Python part, I can do

poetry build

and it will create a Python “wheel” inside the dist directory. For those not familiar with this, it is basically a zip file that contains everything required to install the program. Then, an end-user can do

pip install my-program-version-pyversion.whl

and they’re done.

I was thinking that it would be really nice to have something similar in pio.

pio dist
pio run my-program-arduino-uno.pio

Regards

If I understand you correctly, you want to build the program once on your computer, then pack the compilation result in some archive form and distribute that, then pio is supposed to take that archive form and upload it to the target microcontroller?

Well that’s partly possibly and partly has some caveats. In order to upload the program, PIO must download the upload tools (e.g., avrdude, esptool, bossac, openocd, …) for the host architecture. That cannot be easily offline packaged and be cross-platform. PIO will handle this itself.

What is possible is uploading without re-building the project. Practically every platform (in PlatformIO speak, the microcontroller platform, such as atmelavr, espressif8266, espressif32, …) implements the build target nobuild, meaning that no compilation is attempted and the previous compilation result (firmware.bin, firmware.elf in the .pio\build\<environment> folder) are used to directly upload it. See Upload Latest build without a Compile/Link.

So a packaging like that can work by running pio run once to build the firmware image, removing some non-needed build artifacts (.pio\build\<environment>\*everything that's not firmware elf or bin or filesystem images in case of ESP8266/ESP32*), zipping the entire project folder, then unzipping that on the other end and running pio run -t nobuild -t upload to do a upload-without-recompilation. Then it should use your previously, locally compiled firmware.bin and friends for upload, and will install upload tools needed for the host computer as needed.

Of course, non-PIO ways exist too and might be more straight-forward. If your project just results in a firmware.bin that needs to be uploaded, you can again use pio run to produce this file once, then stick in a ZIP file together with a text file which says which upload tool needs to be installed and which upload command to run. No PIO involved then and less overhead, but also way less flexible.

1 Like

This is an idea that I propose, I do not look for an immediate solution nor a workaround. What I say is that it would be nice if PIO allowed for a simple way to do that.

In order to upload the program, PIO must download the upload tools (e.g., avrdude, esptool, bossac, openocd, …) for the host architecture.

Yep. The same way that pip downloads the requirements/dependencies, or npm for JavaScript, gem for Ruby, … Ideally, the created package would contain some metadata so that PIO can download the necessary tools and upload to the target (e.g. include the platform.ini, or a part of it).