Configuring wifi headless with connmanctl on LibreELEC via SSH

Because I love doing things quite backwards, I found myself in a predicament: I had only a wired direct connection between my laptop and the Raspberry Pi where I was running LibreELEC. Using mDNS I could connect to it directly connected at LibreELEC.local, and that's great...

But I wanted to join it to a WiFi network, and I only had a not-great 6-button remote control to plug into the Pi, so entering in long passwords via the UI (if that's even possible without a keyboard?) was not something I wanted to attempt.

Since I could ssh [email protected], I figured I'd connect to the available WiFi network, so it would be more convenient to update the device and put more content on it. Not to mention it expands Kodi's capabilities if you give it an Internet connection!

Enter ConnMan

LibreELEC uses ConnMan to manage network interfaces, and setting WiFi is a little strange, but doable:

While logged into the LibreELEC machine, enter connmanctl to get into the ConnMan shell.

Then do the following:

# scan for access points
connmanctl> scan wifi

# list found access points
connmanctl> services
[list should appear here, with long unique hashes]

# enable ConnMan's agent to provide the WiFi password
connmanctl> agent on

# connect to the WiFi network
connmanctl> connect wifi_[long hash here for your AP]_managed_psk

# enter in the password when it prompts for "Passphrase?"
# wait for it to connect...

# then quit connmanctl
connmanctl> quit

Run ip a to check what the WiFi IP is; you can also connect via LibreELEC.local on the WiFi network, as long as it supports mDNS.

Comments

See https://github.com/raspberrypi/bookworm-feedback/issues/72 for the howto of how to modify your downloaded image to do this hands-off to make a reusable pre-configured image without using rpi-imager. Basically you modify cmdline.txt to add some options, then drop in a firstrun.sh script to do anything you want it to do. It'll get run then deleted on firstboot and the system will come up fine hands-off.

The 64 bit with desktop example has:
```
console=serial0,115200 console=tty1 root=PARTUUID=f6a7c4bd-02 rootfstype=ext4 fsck.repair=yes rootwait quiet init=/usr/lib/raspberrypi-sys-mods/firstboot splash plymouth.ignore-serial-consoles
```

Add the options
```
init=/usr/lib/raspberrypi-sys-mods/firstboot systemd.run=/boot/firstrun.sh systemd.run_success_action=reboot systemd.unit=kernel-command-line.target
```

Tests ok with both lite and desktop versions of the 10-10-2023 raspi os.