How to set device id when new device is added

Hi,
I wonder how you figure out which physical device corresponds to what device in the balena GUI? When I add a new device to the fleet, it has an autogenerated ID. If only one device is added, you can probably find a device with a GUID-like identifier and then change the device name to something recognizable. But what if multiple users add devices in parallel?
Often, the manufacturer prints a unique identifier on the device. This identifier can probably be somehow accessible in the device via an environment variable or a file’s content.
I wonder, is there any way to assign it as a Balena ID when a device is being added? Or enter it as an alias or user-defined ID?

If you pre-register the device, you can set the ID when registering it.

balena device register "$FLEET_ID" --uuid="$(uuidgen | tr -d '-')"

You would need to configure the device with these details to link it properly, meaning along with the registration you would

  • fetch fleet config
  • combine this into a device config
  • write device config into the device image (balena os configure or seemingly the newer balena config inject)

The first two steps may be possible to combine- balena config generate didn’t exist when I wrote my own provisioning tool to avoid the balena CLI.

You’ll notice that you will no longer be able to use the same “blank” Balena OS image to flash any device, but would need to pre-register and configure an image with device specific details before flashing that onto the device storage media. Our provisioning tooling caches a blank image and reconfigures a copy of it before flashing.

Another approach that we also do is to read the hardware ID from DMI and send out a message with that and the Balena ID (injected as BALENA_DEVICE_UUID) to the cloud so that we can link it up in our own systems.

It would be great if it was possible to customise the registering process directly on the device, but unfortunately I don’t think there is any way to do this at the moment, and I wouldn’t expect it to change any time soon.

Hope that’s helpful.