would be to preregister each device with our balenaCloud
Expanding on this point, there are detailed instructions in this CLI masterclass section:
By knowing the device UUID in advance – even in advance of preloading, as you could generate the UUID alongside the one-time-use key of your own cloud platform – you might then be able to avoid storing the one-time-use key on the device in the first place. Just map the device UUID to the key in your own cloud platform database.
I have just realised that
BALENA_DEVICE_NAME_AT_INIT is not populated on a preloaded device […]
I gather that supervisor
v11.7.0 or later (shipped with balenaOS
v2.52.4 or later) started taking into account the
initialDeviceName field in
config.json (as written by
balena os configure). Could it be that you were testing it with an older version?
[…] and I am using that [BALENA_DEVICE_NAME_AT_INIT] as a device identifier in quite a bit of my code
As with the suggestion for replacing the one-time-use key with a pre-registered device UUID, you might also consider using the UUID as the device identifier instead of
BALENA_DEVICE_NAME_AT_INIT. I gather that there is another env var,
Talking of env vars, from some of your comments, it sounds like you’re already using application environment variables. Keep in mind that there are also device-specific environment variables that could be part of the solution: https://www.balena.io/docs/learn/manage/serv-vars/#device-environment-and-service-variables
These device-specific env vars are not available before the first boot, though (as far as I know).