Getting Bluetooth going in WSL 2 is typically a fair amount of work and it's a minefield. Hopefully this is helpful for someone somewhere!
Initialize.ps1 simplifies this by doing the following...
- Ensures WSL2 is setup with a default Ubuntu distro
- Creates a temp distro to compile the kernel with Bluetooth support
- Creates the .wslconfig file to point at the new kernel
- Reloads WSL to apply the new kernel
- Adds the app user UID 1654 (Specific to .NET containers running as non-root user)
- Ensures the bluetooth group is created
- Adds the app user to the bluetooth group
- Ensures dbus is running
- Installs bluez
- Ensures bluetooth is running
- Installs linux-tools-virtual
- Installs usbipd-win
- Installs docker desktop
To run this...
- Open the solution in Visual Studio 2022
- Run "Scripts/Development/Initialize.ps1" in the package manager window
- Attach your bluetooth device to the ubuntu distro
- Run bluetoothctl inside the .NET container and it will work
If you have any issues running the script...
- Make sure you can execute powershell with "Set-ExecutionPolicy RemoteSigned"
- Make sure the line endings in BuildKernel.sh are Unix (LF), Notepad++ makes it simple to check/fix it.