How to interpolate CLI command output in the ini config value?

In my platformio.ini file I have something like this:

ota_upload_password = foobar
ota_upload_password_md5 = 3858f62230ac3c915f300c664312c63f

build_flags =
    '-D OTA_UPLOAD_PASSWORD_MD5="${ota_upload_password_md5}"'

upload_flags =
    --auth=${ota_upload_password}

As you can see, I have to manually synchronise ota_upload_password and ota_upload_password_md5 ā†’ and I would like to have it done automatically.

I can generate MD5 in CLI like this:

āœ— md5 -q -s foobar
3858f62230ac3c915f300c664312c63f

Question: how do I do that from within platformio.ini config?

I guess Iā€™m looking for something like this:

ota_upload_password = foobar

build_flags =
    '-D OTA_UPLOAD_PASSWORD_MD5="`md5 -q -s ${ota_upload_password}`"'

upload_flags =
    --auth=${ota_upload_password}

See

https://docs.platformio.org/en/latest/projectconf/sections/env/options/build/build_flags.html#dynamic-build-flags

2 Likes

Thanks! It is exactly what I was looking for:

ota_upload_password = foobar

build_flags =
    !echo '-D OTA_UPDATE_PASSWORD_MD5=\\"'$(md5 -q -s ${ota_upload_password})'\\"'
1 Like