Esempio n. 1
0
        private async Task BuildServer(ClientPage clientPage)
        {
            try
            {
                adapter = CrossBleAdapter.Current;
                server  = await adapter.CreateGattServer();

                Plugin.BluetoothLE.Server.IGattService service = server.CreateService(Guid.Parse("569A1101-B87F-490C-92CB-11BA5EA5167C"), true);
                BuildCharacteristics(service, Guid.Parse("569A2003-B87F-490C-92CB-11BA5EA5167C"), clientPage, CharacteristicsType.TX_Write);
                BuildCharacteristics(service, Guid.Parse("569A2002-B87F-490C-92CB-11BA5EA5167C"), clientPage, CharacteristicsType.RX_Notify);
                BuildCharacteristics(service, Guid.Parse("569A2001-B87F-490C-92CB-11BA5EA5167C"), clientPage, CharacteristicsType.TX_Write);
                BuildCharacteristics(service, Guid.Parse("569A2000-B87F-490C-92CB-11BA5EA5167C"), clientPage, CharacteristicsType.RX_Notify);
                server.AddService(service);

                //Plugin.BluetoothLE.Server.IGattCharacteristic characteristic = service.AddCharacteristic
                //(
                //    Guid.NewGuid(),
                //    CharacteristicProperties.Read | CharacteristicProperties.Write | CharacteristicProperties.WriteNoResponse,
                //    GattPermissions.Read | GattPermissions.Write
                //);

                //Plugin.BluetoothLE.Server.IGattCharacteristic notifyCharacteristic = service.AddCharacteristic
                //(
                //    Guid.NewGuid(),
                //    CharacteristicProperties.Indicate | CharacteristicProperties.Notify,
                //    GattPermissions.Read | GattPermissions.Write
                //);

                adapter.Advertiser.Start(new AdvertisementData
                {
                    LocalName = "My GATT"
                });
            }
            catch (Exception ex) {
                Exception exception = ex;
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Waits for bluetooth adapter to be in an acceptable state and then tries to create a gatt server
 /// </summary>
 /// <param name="adapter"></param>
 /// <returns></returns>
 public static IObservable <IGattServer> WhenReadyCreateServer(this IAdapter adapter) => adapter
 .WhenStatusChanged()
 .Where(x => x == AdapterStatus.PoweredOn)
 .Select(_ => adapter.CreateGattServer())
 .Switch();