Compile Time Arguments?

Hello everyone,

I am fairly new to using PlatformIO to do embedded work, so I apologize if this is an obvious question, I just can’t figure it out on my own.

For context, I am using a Heltec AB01 board at work for LoraWan stuff, and we want to deploy a bunch of them to collect data. The only drawback with our method is that with each new board, I have to go into the code, type in the new devEUI, appEUI, and appKey, then recompile the program. This is fairly tedious, especially when we plan to scale up to a lot of devices. I am attempting to write a program to automate this using “pio run” and reading from a CSV of IDs, but one issue has me stuck.

My main question is if there is a way to have arguments which are passed into variables each compile that can be easily modified?

For example, in a standard C program, you might have an int main (int argc, char * argv[]) and then when you run the code you can tack on a file name or switch in the command line, but I am lost as to if there is an equivalent version for PIO development.

Right now, my best idea is to have the IDs read, then I have a separate identity.h in which I was going to overwrite the values, but it seems clunky to try and write to a .h file like that.

If anyone has any better solutions than mine, I’d really appreciate it!

Thank you,

See What is the best practice to build firmware for IoT nodes with node specific credentials.

If you want to keep the firmware.elf constant, you can also just put your credentials in the LittleFS and have your code read it from there. That way, for each node, you just have to update a file in e.g. data/credentials.txt and do a pio run -t uploadfs, much faster than a firmware rebuild.

Thank you so much, you’re a lifesaver!