Hi everyone,
it’s my first post, apologies if I missed some posting rules, but here’s what I am having trouble with.
I want to preconfigure (and maybe update later on) certain values for the ESP32-based project. I found there’s a Preferences library, which does the trick. Now, how do I go about actually preconfiguring the data - key/value pairs and then flashing them to the board?
What I am doing at the moment is I am [mis]using a mass_mfg/mfg_gen.py for this purpose then flashing the generated binary file manually with a command like ‘esptool.py -p COM9 write_flash 0x9000 bin\MS-1.bin’
Now I wonder, is there an integrated in the VSCODE/PIO way to do so? I don’t have a need to do actual mass manufacturing, what I want is I generate the configuration for one device and flash it to be able to update it independently of the program code. Can it be done without programming this thing as custom scripts? It sounds to me like an obvious thing to do, but I cannot find how to go about it.
If the initial values are known and unchanging, can the Preferences library detect the “Value for Key has not been set yet” situation in which you then can store your default values on bootup? Then the entire discussion is already over.
If they are unique for each board, in some sort of mass-manifacture setting (I would actually not recommend PlatformIO for such extremely critcial things), then there are multiple options:
1: If you want it to be generated and uploaded in each upload process, then the builder script is capable of accepting extra flash images as python tuple of (address, path) form inside env["FLASH_EXTRA_IMAGES"]. While I have not tested this, it should be accessible and appendable from within an extra script.
2: You can create a custom PlatformIO target (=task) per documentation and do the generating and flashing there.
Just to get it straight: I am going to store things like WIFI credentials, so I don’t want to commit it as it can change any time, without need to change the code.
Thanks for the hint about FLASH_EXTRA_IMAGES, I will check it. This doesn’t answer the generation part though.
Don’t want to start a holy war, but how do people normally store WIFI credentials if they want to be able to preconfigure the values, i.e. not only update them via Web Interface, OTA or similar? I am new to the MCU world, but I assumed, storing configuration separately from code is an obvious thing as well as being able to set the initial configuration outside of code.
You have to be inside an extra_script (aka, Python script) to append to FLASH_EXTRA_IMAGES) anyways, so in that very script file, you do the generation by calling into mfg_gen.py as before (env.Execute() with $PYTHONEXE etc.). The result file of that is one argument of the FLASH_EXTRA_IMAGES_TUPLE.