Device not joining fleet after using Balena CLI to write SD card

Greetings all! I’m trying to speed up provisioning of a fleet of Raspberry Pi devices using the Balena CLI, and running into an issue where the device doesn’t join the designated fleet after booting.

I’m on Balena CLI version 12.48.7

Here are the commands I’m using (from following the CLI Advanced Masterclass):

Download a raw os image:

balena os download raspberrypi4-64 --output image.img --version v2.83.10+rev1.dev
Getting device operating system for raspberrypi4-64
The image was downloaded successfully

Configure the image:

balena os configure image.img --config generated_config.json --fleet myFleet
Configuring operating system image

Write the image to an SD card:

balena os initialize image.img --type raspberrypi4-64 --drive '\\.\PhysicalDrive2' --yes
Initializing device
Note: Initializing the device may ask for administrative
because we need to access the raw devices directly.
Going to erase \.\PhysicalDrive2.
Writing Device OS [========================] 100% eta 0s
Validating Device OS [========================] 100% eta 0s
You can safely remove \.\PhysicalDrive2 now

Here are the contents of generated_config.json (with ssid/key changed to protect the innocent):

{
   "network": "wifi",
   "wifiSsid": "mySSID",
   "wifiKey": "myPassword"
}

These steps all complete without errors, and the Pi boots from the SD card as expected. Once it’s booted, I can see that it has joined the wifi network, as it comes up with the scan command:

balena scan
Scanning for local balenaOS devices… Reporting scan results
-
host: a3f6878.local
address: 192.168.86.120
osVariant: development
dockerInfo:
Containers: 1
ContainersRunning: 1
ContainersPaused: 0
ContainersStopped: 0
Images: 2
Driver: overlay2
SystemTime: 2021-09-08T03:05:32.872105978Z
KernelVersion: 5.10.31-v8
OperatingSystem: balenaOS 2.83.10+rev1
Architecture: aarch64
dockerVersion:
Version: 19.03.24
ApiVersion: 1.40

However, when I run balena devices to see if it has joined the Fleet, I get an empty list:

balena devices --v13
ID UUID DEVICE NAME DEVICE TYPE FLEET STATUS IS ONLINE SUPERVISOR VERSION OS VERSION DASHBOARD URL

I’ve tried waiting up to an hour to see if it ever joins, and I never see the newly commissioned device come up in the device list.

I have found that I can force it to join the fleet by its IP address with:

balena join 192.168.86.120 --fleet myFleet
←[32m?←[39m ←[1mCheck for updates every X minutes←[22m←[0m ←[0m←[2m(10) ←[22m←[41D←[41C
… bunch of other garbled output trimmed…
| [192.168.86.120] Configuring…←[2K←[1G/ [192.168.86.120] Configuring…←[2K←[1G←[32m[Success]←[39m Device successfully joined balena-cloud.com!

At this point, if I run balena devices again, I see it show up as expected in the device list.

I have two questions:

  1. Am I doing something incorrectly in the os image configuration or initialization process that’s keeping the device from automatically joining the fleet when it boots up?
  2. What’s with all the garbage on the output of the balena join command? Is this a known issue?

Thanks for the help all!
-Robert

The config file doesn’t contain the UUIDs or other details needed to join a fleet. It sounds a bit like you are making the config file yourself. You need to generate the config file using the CLI: balena CLI Documentation - Balena Documentation

There are also ways to directly configure an image instead of generating a config file and then injecting it. Have a look through the other Balena CLI config commands for more info.

Thanks for the help Maggie (and sorry for the slow response - I had given up and started working on other things for a while).

I was able to get this working (sort of) by skipping the .json config file altogether, and just feeding my config into balena os configure with command line options (--config-network wifi --config-wifi-key).

I still have two issues that I haven’t been able to resolve, but that I can work around for now:

[1] balena os configure doesn’t accept a wifi SSID containing spaces:

balena os configure image/image.img --fleet myfleet --config-network wifi --config-wifikey anchorman --config-wifi-ssid ‘I Love Lamp’
‘C:\Program’ is not recognized as an internal or external command, operable program or batch file.

I’ve resorted to just omitting the config-wifi-ssid flag, and entering the SSID interactively. Not ideal, but it’ll work for now.

[2] I haven’t been able to get this workflow to work with Development images.

Everything works fine with a Production image (e.g. v2.85.2+rev3.prod), but the device never joins my fleet with a Development image (e.g. v2.85.2+rev3.dev).

The config and flashing operations appear to proceed identically (no errors seen in either case), but no matter how long I wait the Raspberry Pi with a Dev image never joins the fleet. It does show up on balena scan, so I know it was flashed correctly and has booted.

Since this CLI-based workflow is mostly for flashing production images to boards, I can just use Balena Etcher to flash Development images for the time being. I’m curious if anyone has advice on how to get this working with Development images, however.