Esempio n. 1
0
 private void StartServer()
 {
     gattServer.AddService(buzzerService);
     //start advertising the server
     CrossBleAdapter.Current.Advertiser.Start(new AdvertisementData
     {
         LocalName    = serverName,
         ServiceUuids = services
     });
 }
Esempio n. 2
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;
            }
        }