How to make platformio.ini configurable?

If I want to make a project available publicly, what is the best way to make some values configurable for another user of the project? Things like passwords, hosts, etc? I’ve done some things via environment variable specified outside of VSCode IDE, but that seems somewhat painful. What would be awesome would be some kind of optional “properties file” (yes… Java background) that would be sourced for all platformio commands but could be ignored from source control.

This seems like something others would want, but I’m not seeing anything like this.

Thanks,
Craig

The platformio.ini can include other .ini files which you can .gitignore but still access from the environments of the platformio.ini. See extra_configs.

So that would make it possible to have file with a e.g. [credentials] section that is then accessed in other parts as ${credentials.username} or whatever to generate -D macros from or to be used in upload commands.

If the credentials should just be visible in code, they should be put in the code. You can e.g. create a header file (or template for), so the could would do

#include "credentials.h"

void some_func() {
   /* use macros declared in header */
}

with credentials_template.h

#ifndef CREDENTIALS_H
#define CREDENTIALS_H

/* your actual data here */
#define MY_SSID "ABCD"
#define MY_PASSWORD "DEFGHIJKLMNOP"

#endif

and then add the credentials.h to the .gitignore while telling users to duplicate the template file as credentials.h and input their real data there. That way it also automatically stays in the “code realm” and musn’t be taken care of by the build-system specifically - just plain includes and macros.

1 Like

@maxgerhardt - You continue to provide the perfect direction!

I actually originally had exactly what you showed using “code” with a template. However, all of that is now prompted from within the app now. This is more about configuring custom tasks and the extra_configs is exactly what I was looking for, but somehow not seeing.

Thank you!