Samples/BluetoothLE/cs/Scenario3_ServerForeground.xaml.cs
/// <summary>
/// Uses the relevant Service/Characteristic UUIDs to initialize, hook up event handlers and start a service on the local system.
/// </summary>
/// <returns></returns>
Uses the relevant Service/Characteristic UUIDs to initialize, hook up event handlers and start a service on the local system.
Uses the relevant Service / Characteristic UUIDs to initialize hook up event handlers and start a service on the local system .
private async Task<bool> ServiceProviderInitAsync()
        {
            GattServiceProviderResult serviceResult = await GattServiceProvider.CreateAsync(Constants.OnboardingServiceUuid);
            if (serviceResult.Error == BluetoothError.Success)
            {
                serviceProvider = serviceResult.ServiceProvider;
            }
            else
            {
                rootPage.NotifyUser($"Could not create service provider: {serviceResult.Error}", NotifyType.ErrorMessage);
                return false;
            }
            GattLocalCharacteristicResult result = await serviceProvider.Service.CreateCharacteristicAsync(
                Constants.ProtocolVersionCharacteristicUuid, Constants.gattProtocolVersionParameters);
            if (result.Error == BluetoothError.Success)
            {
                result.Characteristic.ReadRequested += ProtocolVersionCharacteristic_ReadRequestedAsync;
            }
            else
            {
                rootPage.NotifyUser($"Could not create operand1 characteristic: {result.Error}", NotifyType.ErrorMessage);
                return false;
            }
            result = await serviceProvider.Service.CreateCharacteristicAsync(
                Constants.RossVersionCharacteristicUuid, Constants.gattRossVersionParameters);
            if (result.Error == BluetoothError.Success)
            {
                result.Characteristic.ReadRequested += RossCharacteristic_ReadRequestedAsync;
            }
            else
            {
                rootPage.NotifyUser($"Could not create operand2 characteristic: {result.Error}", NotifyType.ErrorMessage);
                return false;
            }
            result = await serviceProvider.Service.CreateCharacteristicAsync(
                Constants.WifiListRequestCharacteristicUuid, Constants.gattWifiListParameters);
            if (result.Error == BluetoothError.Success)
            {
                result.Characteristic.ReadRequested += WifiListCharacteristic_ReadRequestedAsync;
            }
            else
            {
                rootPage.NotifyUser($"Could not create operator characteristic: {result.Error}", NotifyType.ErrorMessage);
                return false;
            }
            result = await serviceProvider.Service.CreateCharacteristicAsync(
                Constants.OnboardingResultCharacteristicUuid, Constants.gattOnboardingResultParameters);
            if (result.Error == BluetoothError.Success)
            {
                resultCharacteristic = result.Characteristic;
                resultCharacteristic.ReadRequested += OnboardingStatusCharacteristic_ReadRequestedAsync;
            }
            else
            {
                rootPage.NotifyUser($"Could not create result characteristic: {result.Error}", NotifyType.ErrorMessage);
                return false;
            }
            result = await serviceProvider.Service.CreateCharacteristicAsync(
                Constants.OnboardingRequestCharacteristicUuid, Constants.gattOnboardingRequestParameters);
            if (result.Error == BluetoothError.Success)
            {
                result.Characteristic.WriteRequested += OnboardingRequestCharacteristic_WriteRequestedAsync;
            }
            else
            {
                rootPage.NotifyUser($"Could not create result characteristic: {result.Error}", NotifyType.ErrorMessage);
                return false;
            }
            GattServiceProviderAdvertisingParameters advParameters = new GattServiceProviderAdvertisingParameters
            {
                IsConnectable = peripheralSupported,
                IsDiscoverable = true
            };
            serviceProvider.AdvertisementStatusChanged += ServiceProvider_AdvertisementStatusChanged;
            serviceProvider.StartAdvertising(advParameters);
            return true;
        }
private async Task < bool > ServiceProviderInitAsync ( ) { GattServiceProviderResult serviceResult = await GattServiceProvider . CreateAsync ( Constants . OnboardingServiceUuid ) ; if ( serviceResult . Error == BluetoothError . Success ) { serviceProvider = serviceResult . ServiceProvider ; } else { rootPage . NotifyUser ( $" Could not create service provider:  { serviceResult . Error } " , NotifyType . ErrorMessage ) ; return false ; } GattLocalCharacteristicResult result = await serviceProvider . Service . CreateCharacteristicAsync ( Constants . ProtocolVersionCharacteristicUuid , Constants . gattProtocolVersionParameters ) ; if ( result . Error == BluetoothError . Success ) { result . Characteristic . ReadRequested += ProtocolVersionCharacteristic_ReadRequestedAsync ; } else { rootPage . NotifyUser ( $" Could not create operand1 characteristic:  { result . Error } " , NotifyType . ErrorMessage ) ; return false ; } result = await serviceProvider . Service . CreateCharacteristicAsync ( Constants . RossVersionCharacteristicUuid , Constants . gattRossVersionParameters ) ; if ( result . Error == BluetoothError . Success ) { result . Characteristic . ReadRequested += RossCharacteristic_ReadRequestedAsync ; } else { rootPage . NotifyUser ( $" Could not create operand2 characteristic:  { result . Error } " , NotifyType . ErrorMessage ) ; return false ; } result = await serviceProvider . Service . CreateCharacteristicAsync ( Constants . WifiListRequestCharacteristicUuid , Constants . gattWifiListParameters ) ; if ( result . Error == BluetoothError . Success ) { result . Characteristic . ReadRequested += WifiListCharacteristic_ReadRequestedAsync ; } else { rootPage . NotifyUser ( $" Could not create operator characteristic:  { result . Error } " , NotifyType . ErrorMessage ) ; return false ; } result = await serviceProvider . Service . CreateCharacteristicAsync ( Constants . OnboardingResultCharacteristicUuid , Constants . gattOnboardingResultParameters ) ; if ( result . Error == BluetoothError . Success ) { resultCharacteristic = result . Characteristic ; resultCharacteristic . ReadRequested += OnboardingStatusCharacteristic_ReadRequestedAsync ; } else { rootPage . NotifyUser ( $" Could not create result characteristic:  { result . Error } " , NotifyType . ErrorMessage ) ; return false ; } result = await serviceProvider . Service . CreateCharacteristicAsync ( Constants . OnboardingRequestCharacteristicUuid , Constants . gattOnboardingRequestParameters ) ; if ( result . Error == BluetoothError . Success ) { result . Characteristic . WriteRequested += OnboardingRequestCharacteristic_WriteRequestedAsync ; } else { rootPage . NotifyUser ( $" Could not create result characteristic:  { result . Error } " , NotifyType . ErrorMessage ) ; return false ; } GattServiceProviderAdvertisingParameters advParameters = new GattServiceProviderAdvertisingParameters { IsConnectable = peripheralSupported , IsDiscoverable = true } ; serviceProvider . AdvertisementStatusChanged += ServiceProvider_AdvertisementStatusChanged ; serviceProvider . StartAdvertising ( advParameters ) ; return true ; }
Uses the relevant Service/Characteristic UUIDs to initialize, hook up event handlers and start a service on the local system.
Uses the relevant Service / Characteristic UUIDs to initialize hook up event handlers and start a service on the local system .
// BT_Code: Initialize and starting a custom GATT Service using GattServiceProvider. //       // Add presentation format - 32-bit unsigned integer, with exponent 0, the unit is unitless, with no company description //       GattPresentationFormat intFormat = GattPresentationFormat.FromParts( //           GattPresentationFormatTypes.UInt32, //           PresentationFormats.Exponent, //           Convert.ToUInt16(PresentationFormats.Units.Unitless), //           Convert.ToByte(PresentationFormats.NamespaceId.BluetoothSigAssignedNumber), //           PresentationFormats.Description); //       Constants.gattWifiListParameters.PresentationFormats.Add(intFormat); // BT_Code: Indicate if your sever advertises as connectable and discoverable. // IsConnectable determines whether a call to publish will attempt to start advertising and  // put the service UUID in the ADV packet (best effort) // IsDiscoverable determines whether a remote device can query the local device for support  // of this service
None