Getting Started
This guide gets a Bluetooth application running. The fastest route is the desktop stub stack, which runs the shipped demos and your own code on Windows with no Bluetooth hardware attached — so start there, then move to a display.
Table of Contents
Add the Extension to Your Project
Run the Classic Demo on Windows
Add the Extension to Your Project
Adding the extension is two steps: add it through the OpenPV Developer Toolkit's Plugin Manager, and
reference the Ahsoka.Extensions.Bluetooth package in your application. Both are needed — the application
will not publish without the package reference.
Reference it without a version. Opening the project in the Toolkit generates a Directory.Packages.props
that carries the version centrally, so a Version attribute on the PackageReference is an error:
<ItemGroup>
<PackageReference Include="Ahsoka.Extensions.Bluetooth" />
</ItemGroup>
Once added, BluetoothService and BLEService are registered with AutoStart behavior, so they start
with your application. There is nothing to start yourself — you only construct the clients you want.
If you use the audio profiles — AudioSink or AudioSource — add the Audio extension the same way:
Ahsoka.Extensions.AudioManager in the Plugin Manager and as a package reference. It starts and owns the
platform's audio server, which A2DP depends on; this extension does not start it. Without the Audio
extension in your application, audio profile connections may fail and there is no audio routing. The
Classic demo includes it.
To edit adapter and profile configuration through a UI, select the Bluetooth extension on the Extensions tab and click Configure Extension…. See Configuration Reference.

Run the Classic Demo on Windows
The extension ships two implementations of every platform-facing operation: the real BlueZ one and a desktop stub. The stubs simulate adapters, devices, pairing, connections, and even a media player — enough to exercise the full notification flow with no radio present.
This is not a crippled mode. The desktop AudioSink stub runs a player-info loop that emits track changes, and the AudioSource stub implements the complete volume handshake. Your notification handling, UI binding, and state machines can all be built and debugged before you touch hardware.
Which implementation runs is decided by configuration, not by your code:
| Where | Setting | Result |
|---|---|---|
WindowsHardwareConfiguration.json |
bluetoothInfo.bluetoothAdapters[].stack = "Desktop" |
Desktop stubs |
BluetoothConfig.json |
"stack": "StackDesktop" |
Desktop stubs |
BluetoothConfig.json |
"stack": "StackBluez" |
Real BlueZ over D-Bus |
You can read which one you got at runtime, which is what the demo does to decide whether to enable adapters eagerly:
var config = bluetoothClient.GetBluetoothConfiguration();
if (config.Stack == SupportedBluetoothStack.StackDesktop)
EnableAdapters();
Open the Ahsoka.CS.BluetoothClassic demo, build, and run. You get one tab set per configured
adapter, with panels appearing only for the profile services that adapter declares — see
The Demos.
Connect a Client
Register your notification callback through the dispatcher, then call Start():
using Ahsoka.Core;
using Ahsoka.Services.Bluetooth;
using Ahsoka.Services.Bluetooth.Proto;
var bluetoothClient = new BluetoothServiceClient();
Dispatcher.Default.RegisterCallback<AhsokaClientBase<BluetoothMessageTypes.Ids>.AhsokaNotificationArgs>(
OnBluetoothNotification,
bluetoothClient);
bluetoothClient.Start();
Start() is optional — a client starts itself on its first call. Call it up front anyway, right after
registering the callback: notifications only flow once the client is started, so starting it yourself
avoids missing any.
Registering through Dispatcher.Default marshals notifications onto your dispatcher thread, which is
what you want in an application with a UI. Every notification arrives through one callback, and you
dispatch on TransportId — which is strongly typed as the message-id enum, so no cast is needed. The
payload arrives as NotificationObject, so pattern-match it:
static void OnBluetoothNotification(
object sender,
AhsokaClientBase<BluetoothMessageTypes.Ids>.AhsokaNotificationArgs e)
{
switch (e.TransportId)
{
case BluetoothMessageTypes.Ids.AdapterEnabled
when e.NotificationObject is BluetoothAdapterState adapterState:
// adapterState.IsEnabled tells you whether it actually came up
break;
case BluetoothMessageTypes.Ids.DiscoveredDeviceAdded
when e.NotificationObject is BluetoothDeviceDiscoveryInfo discovered:
// discovered.DeviceName, discovered.DeviceMacAddress, discovered.DeviceClass
break;
case BluetoothMessageTypes.Ids.PairingRequested
when e.NotificationObject is BluetoothPairingNotification pairing:
// pairing.Passkey is what you show the user
break;
}
}
See Core Concepts for the full notification model and the per-adapter convention.
Enable an Adapter
Nothing happens until an adapter is powered on. EnableAdapter takes the adapter index and the
pairing agent timeout in seconds:
const int AdapterIndex = 0;
const int PairingAgentTimeout = 30;
bluetoothClient.EnableAdapter(AdapterIndex, PairingAgentTimeout);
This is asynchronous. Wait for the AdapterEnabled notification — and check its IsEnabled flag,
because AdapterEnabled also reports failure to come up — before issuing discovery or connection
requests. Do not assume the adapter is up when the call returns.
To be findable by a phone, the adapter also has to be discoverable and pairable:
// Discoverable for 180 seconds
bluetoothClient.SetAdapterDiscoverable(new BluetoothAdapterDiscoverableRequest
{
AdapterIndex = AdapterIndex,
IsDiscoverable = true,
DiscoverableTimeout = 180
});
// Pairable indefinitely
bluetoothClient.SetAdapterPairable(new BluetoothAdapterPairableRequest
{
AdapterIndex = AdapterIndex,
IsPairable = true,
PairableTimeout = 0
});
DiscoverableTimeout and PairableTimeout are both uint?. A value of 0 means stay on
indefinitely; omitting the property entirely uses the adapter's default. Both changes are confirmed
by AdapterDiscoverableChanged and AdapterPairableChanged notifications rather than by the call
returning, so drive your UI from those.
Discover and Pair a Device
Discovery is time-boxed. Devices arrive one DiscoveredDeviceAdded notification at a time, and
DiscoveryComplete marks the end of the window:
bluetoothClient.StartDiscovery(new BluetoothDiscoveryRequest
{
AdapterIndex = AdapterIndex,
DiscoveryTimeout = 30
});
To pair, hand back the BluetoothDeviceDiscoveryInfo you received from discovery:
bluetoothClient.RequestToPair(new BluetoothPairRequest { DeviceInfo = discovered });
Pairing needs your application in the loop, because the display acts as the pairing agent. When
confirmation is required you get PairingRequested with a passkey to display, and you must answer:
case BluetoothMessageTypes.Ids.PairingRequested
when e.NotificationObject is BluetoothPairingNotification pairing:
// Show pairing.Passkey to the user and wait for their choice, then:
bluetoothClient.SendPairingConfirmation(new BluetoothPairingConfirmation
{
AdapterIndex = pairing.AdapterIndex,
Confirmed = true
});
break;
When pairing.DisplayOnly is set, the user types the passkey on the phone instead: show it and do not
answer. If you never answer a confirmation, the pairing agent times out after the interval you passed to
EnableAdapter. PairingComplete and PairingCanceled report the outcome. Full detail in
Adapters, Discovery & Pairing.
Moving to a Display
The production platform is Linux with BlueZ over D-Bus. Three things to know when you deploy:
- Bluetooth Classic is OpenView Pro only. BLE peripheral mode works on Pro and Select, but multi-adapter support, device discovery, the Classic pairing flow, and every Classic profile service require Pro. See Supported & Not Supported.
- Configure the target through the configuration UI, not by hand. Open Configure Extension… on the
Extensions tab and set the stack and each adapter's interface path there; the UI writes the
per-platform
BluetoothConfig.jsonfor you. Hand-editing the JSON works and is occasionally quicker for bulk changes, but the configuration UI is the intended path — it keeps derived values such as Class of Device bit-packing consistent, which is easy to get wrong manually. See Configuration Reference. - Both display platforms run BlueZ 5.84, so BLE feature availability does not vary between them:
| Platform | BlueZ |
|---|---|
| OpenView Pro | 5.84 |
| OpenView Select | 5.84 |
The extension owns and deploys two systemd units, Ahsoka.Bluetooth.service (bluetoothd) and
Ahsoka.Obex.service (obexd). Neither is enabled at boot; enabling an adapter or starting the BLE
stack starts them, and obexd follows bluetoothd automatically through Wants and BindsTo. You do
not manage these yourself.
Ahsoka.Bluetooth.service also declares Wants=Ahsoka.Audio.service and After=Ahsoka.Audio.service, so
the audio stack comes up ahead of Bluetooth — when the Audio extension is part of your application. If it
is not, that unit does not exist and nothing brings the audio server up.
One habit worth adopting before you ship: disable your adapters during application shutdown.
Connection state is delivered by notification and is not replayed on subscribe, so an application
that restarts while a device is still connected has no way to learn about that connection. Severing
links on the way out means there is never stale state to reconcile. The Classic demo calls
DisableAdapters() on exit for exactly this reason.
If something works on the desktop stubs but not on hardware, go to Troubleshooting — most of what is listed there is BlueZ behavior the stubs do not reproduce.
The Demos
Three demos ship inside the package under demos/ and are also in the repository under Demos/:
| Demo | Language | Target | Shows |
|---|---|---|---|
Ahsoka.CS.BluetoothClassic |
C# | Pro only | Adapter control, pairing, phone-side audio, headset-side audio, message access, phonebook |
Ahsoka.CS.BLE |
C# | Pro and Select | GATT peripheral with two attribute-defined services |
Ahsoka.CPP.BLE |
C++ | Pro and Select | The same GATT peripheral from C++ — see the C++ Integration Guide |
The Classic demo ships a Pro platform folder only, because Bluetooth Classic is not supported on Select. Both BLE demos ship Pro and Select folders.
The Classic demo builds its panels from SupportedProfileServiceTypes, so a profile you have not
configured produces no tab. If you expect a Phone or Headset panel and do not see one, the adapter is
not configured for that profile service.