Skip to content

Instantly share code, notes, and snippets.

@neelratanguria
Created April 19, 2024 12:08
Show Gist options
  • Save neelratanguria/e6039e1ff04281476e9c1edabe7bb7f7 to your computer and use it in GitHub Desktop.
Save neelratanguria/e6039e1ff04281476e9c1edabe7bb7f7 to your computer and use it in GitHub Desktop.
BluetoothLEDevice bluetoothLeDevice = await BluetoothLEDevice.FromIdAsync(id);
GattDeviceServicesResult result = await bluetoothLeDevice.GetGattServicesAsync();
if (result.Status == GattCommunicationStatus.Success) {
LogEvent("DEBUG: Services discovered successfully");
foreach (GattDeviceService service in result.Services) {
// Discover characteristics for each service
GattCharacteristicsResult characteristicsResult = await service.GetCharacteristicsAsync();
if (characteristicsResult.Status == GattCommunicationStatus.Success) {
LogEvent("DEBUG: Characteristics discovered for service " + service.Uuid);
foreach (GattCharacteristic characteristic in characteristicsResult.Characteristics) {
// Process each characteristic as needed
// characteristic.Uuid will give you the UUID of the characteristic
}
} else {
LogEvent("ERROR: Failed to discover characteristics for service " + service.Uuid);
}
}
} else {
LogEvent("ERROR: Failed to discover services");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment