Detecting new balena device in the same network


We would like to run an automation installation script for adding a new device.
Our manual steps so far are like this:

  1. Add a new device in the balena cloud
  2. Download & flush the image with balenaEtcher to the SD of the device
  3. Start the device & wait for it to boot
  4. Run script from another PC in the same subnet to generate a certificate for it, and pass it into the container by adding new environment variable.

We would like to automate this process as much as possible.

  1. Is there a way to perform automatically steps (1)-(3) without having to remove the SD from the device? That is we would like it to somehow pull the complete image from cloud & burn it on the device directly, a single script to do it all without manual intervention.

  2. For step (4) we need the UUID of the device for balena CLI. I understand we can see it in the cloud, I’m wondering if there is a way to identify a device automatically, like a device which is connected to the same subnet network as the PC from which the installation script is executed?
    balena scan shows only devices in development mode, not in production mode.

Many Thanks!

Hey @Vitaliy

Most of the steps you mention can be automated with the CLI, there’s detailed information here on how to achieve that (specially the UUID part).

The mounting/unmounting the SD card would be tricky. You’ll probably need some custom hardware that would allow you to switch the SD card from being mounted to the SD slot on your device and your laptop (or whatever HW you use for flashing).

So to summarize, you can automate the pre-registration of your device, configuring the image and flashing it. Then you’ll have to either remove the SD from the flashing HW and mount it on the device or create some sort of SD switching HW that allows you to do that.


Thanks a lot Niko!

Exactly what I was looking for!
Just to add for future readers -

  • all references to rasin in the doc should be replaced with balena
  • etcher can be replaced with balena local flash command for automation.

Thanks again!