Set a custom identifier before first connection

Hey,
I need a way to set an identifier on the device before his first connection. Specifically, I generate a configuration with my Application server and I want to exploit device environment variable to set configuration. Issue is to identify the good device to set the correct configuration. My idea is to set a identifier (custom_id) during flashing process. Use API to identify the UUID according to my custom identifier and set correct environment variable via API.

I want to use device_name but if I understand device_name/ BALENA_DEVICE_NAME_AT_INIT is set by balena supervisor during the first communication with BalenaCloud API. Are there some solutions to force this value ?

In config.json, are there key that corresponding with my need ?

Other solution to configure my device is to generate my custom configuration file and add it on the host OS. Use docker volume to access the config file inside containers. This solution is less flexible and add an other flashing step.

Thanks,
Ben

Hi,
You can use the balena-cli to pre-register a device by using balena device register <MyApp> so that it shows up in the dashboard before you even flash the image. This way you can set the device env vars which will end up being available in the containers beforehand. You can additionally provide your own uuid for the device if you need to.
After registering a device, you can then configure an image to use the generated uuid and finally flash an SD card with it.
Let me point you to the respective documentation pages:
https://www.balena.io/docs/reference/cli/#device-register-application
https://www.balena.io/docs/reference/cli/#os-configure-image

Moreover, as described in the “Going to Production” guide in our docs, you can even use the balena-cli to preload a specific release of your application along with the OS, so that the devices will have the application containers already there on their first boot.
Let me also point you to that guide:

Kind regards,
Thodoris