예제 #1
0
        public void getBle(String usuario)
        {
            Context          actvity          = Application.Context;
            BluetoothManager bluetooth        = (BluetoothManager)actvity.GetSystemService(Context.BluetoothService);
            BluetoothAdapter bluetoothAdapter = bluetooth.Adapter;

            if (bluetoothAdapter.IsEnabled)
            {
                bluetoothAdapter.SetName(usuario);
                BluetoothLeAdvertiser bluetoothLeAdvertiser = bluetoothAdapter.BluetoothLeAdvertiser;
                AdvertiseSettings     settings = new AdvertiseSettings.Builder()
                                                 .SetAdvertiseMode(AdvertiseMode.LowLatency).SetTxPowerLevel(AdvertiseTx.PowerHigh).SetConnectable(true).Build();

                var builder = new AdvertiseSettings.Builder();
                builder.SetAdvertiseMode(AdvertiseMode.LowLatency);
                builder.SetConnectable(true);
                builder.SetTimeout(0);
                builder.SetTxPowerLevel(AdvertiseTx.PowerUltraLow);

                AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
                dataBuilder.SetIncludeDeviceName(true);
                dataBuilder.SetIncludeTxPowerLevel(true);

                bluetoothLeAdvertiser.StartAdvertising(builder.Build(), dataBuilder.Build(), new BleAdvertiseCallback());
                Android.Widget.Toast.MakeText(Application.Context, "Registro de presença automático iniciado.", Android.Widget.ToastLength.Long).Show();
            }
            else
            {
                Android.Widget.Toast.MakeText(Application.Context, "Por gentileza, o Bluetooth deve estar ligado!", Android.Widget.ToastLength.Long).Show();
            }
        }
 private AdvertiseSettings AdvertisingParameters()
 {
     AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
     return(builder.SetAdvertiseMode(AdvertiseMode.Balanced)
            .SetTxPowerLevel(AdvertiseTx.PowerUltraLow)
            .SetConnectable(true)
            .Build());
 }
예제 #3
0
        public void StartAdvertising()
        {
            AdvertiseSettings.Builder builder = new AdvertiseSettings.Builder();
            builder.SetAdvertiseMode(AdvertiseMode.LowLatency);
            builder.SetConnectable(true);
            builder.SetTimeout(0);
            builder.SetTxPowerLevel(AdvertiseTx.PowerHigh);
            AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
            dataBuilder.SetIncludeDeviceName(true);
            //dataBuilder.AddServiceUuid(ParcelUuid.FromString("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"));
            dataBuilder.SetIncludeTxPowerLevel(true);

            this.BluetoothLeAdvertiser.StartAdvertising(builder.Build(), dataBuilder.Build(), this.AdvertiseCallback);
        }
예제 #4
0
        public BleServer(Context ctx)
        {
            _bluetoothManager = (BluetoothManager)ctx.GetSystemService(Context.BluetoothService);
            _bluetoothAdapter = _bluetoothManager.Adapter;

            _bluettothServerCallback = new BleGattServerCallback();
            _bluetoothServer         = _bluetoothManager.OpenGattServer(ctx, _bluettothServerCallback);
            var service = new BluetoothGattService(UUID.FromString("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"),
                                                   GattServiceType.Primary);

            _characteristic = new BluetoothGattCharacteristic(UUID.FromString("d8de624e-140f-4a22-8594-e2216b84a5f2"), GattProperty.Read | GattProperty.Notify | GattProperty.Write, GattPermission.Read | GattPermission.Write);
            _characteristic.AddDescriptor(new BluetoothGattDescriptor(UUID.FromString("28765900-7498-4bd4-aa9e-46c4a4fb7b07"),
                                                                      GattDescriptorPermission.Write | GattDescriptorPermission.Read));

            service.AddCharacteristic(_characteristic);


            _characteristic = new BluetoothGattCharacteristic(UUID.FromString("d8de624e-140f-4a22-8594-e2216b84a5f3"), GattProperty.Read | GattProperty.Notify | GattProperty.Write, GattPermission.Read | GattPermission.Write);
            _characteristic.AddDescriptor(new BluetoothGattDescriptor(UUID.FromString("28765900-7498-4bd4-aa9e-46c4a4fb7b08"),
                                                                      GattDescriptorPermission.Write | GattDescriptorPermission.Read));

            service.AddCharacteristic(_characteristic);
            _bluetoothServer.AddService(service);

            _bluettothServerCallback.CharacteristicReadRequest  += _bluettothServerCallback_CharacteristicReadRequest;
            _bluettothServerCallback.DescriptorWriteRequest     += _bluettothServerCallback_DescriptorWriteRequest;
            _bluettothServerCallback.CharacteristicWriteRequest += _bluettothServerCallback_CharacteristicWriteRequest;
            _bluettothServerCallback.NotificationSent           += _bluettothServerCallback_NotificationSent;
            _bluettothServerCallback.ConnectionStateChange      += _bluettothServerCallback_ConnectionStateChange;
            //           MessagingCenter.Send<BLE202.App, string>((BLE202.App)Xamarin.Forms.Application.Current, "Hi", "Server created!");
            //           _bluetoothAdapter.SetName("Concungungoc");
            BluetoothLeAdvertiser myBluetoothLeAdvertiser = _bluetoothAdapter.BluetoothLeAdvertiser;
            var builder = new AdvertiseSettings.Builder();

            builder.SetAdvertiseMode(AdvertiseMode.LowLatency);
            builder.SetConnectable(true);
            builder.SetTimeout(0);
            builder.SetTxPowerLevel(AdvertiseTx.PowerHigh);
            AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
            dataBuilder.SetIncludeDeviceName(true);
            //dataBuilder.AddServiceUuid(ParcelUuid.FromString("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"));
            dataBuilder.SetIncludeTxPowerLevel(true);
            myBluetoothLeAdvertiser.StartAdvertising(builder.Build(), dataBuilder.Build(), new BleAdvertiseCallback());
        }
예제 #5
0
        public BleServer(Context ctx)
        {
            _bluetoothManager        = (BluetoothManager)ctx.GetSystemService(Context.BluetoothService);
            _bluetoothAdapter        = _bluetoothManager.Adapter;
            _bluettothServerCallback = new BleGattServerCallback();
            _bluetoothServer         = _bluetoothManager.OpenGattServer(ctx, _bluettothServerCallback);

            var service = new BluetoothGattService(UUID.FromString("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"),
                                                   GattServiceType.Primary);

            _characteristic = new BluetoothGattCharacteristic(UUID.FromString("d8de624e-140f-4a22-8594-e2216b84a5f2"), GattProperty.Read | GattProperty.Notify | GattProperty.Write, GattPermission.Read | GattPermission.Write);

            _characteristic.AddDescriptor(new BluetoothGattDescriptor(UUID.FromString("28765900-7498-4bd4-aa9e-46c4a4fb7b07"),
                                                                      GattDescriptorPermission.Read | GattDescriptorPermission.Write));

            service.AddCharacteristic(_characteristic);


            _bluetoothServer.AddService(service);

            _bluettothServerCallback.CharacteristicReadRequest += _bluettothServerCallback_CharacteristicReadRequest;
            _bluettothServerCallback.NotificationSent          += _bluettothServerCallback_NotificationSent;

            Console.WriteLine("Server created!");

            BluetoothLeAdvertiser myBluetoothLeAdvertiser = _bluetoothAdapter.BluetoothLeAdvertiser;

            var builder = new AdvertiseSettings.Builder();

            builder.SetAdvertiseMode(AdvertiseMode.LowLatency);
            builder.SetConnectable(true);
            builder.SetTimeout(0);
            builder.SetTxPowerLevel(AdvertiseTx.PowerHigh);
            AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
            dataBuilder.SetIncludeDeviceName(true);
            byte[] bytes = Encoding.ASCII.GetBytes("jp");
            dataBuilder.AddManufacturerData(1984, bytes);
            dataBuilder.SetIncludeTxPowerLevel(true);

            myBluetoothLeAdvertiser.StartAdvertising(builder.Build(), dataBuilder.Build(), new BleAdvertiseCallback());
        }
        public BleServer(Context ctx)
        {
            _bluetoothManager = (BluetoothManager)ctx.GetSystemService(Context.BluetoothService);
            _bluetoothAdapter = _bluetoothManager.Adapter;

            _bluettothServerCallback = new BleGattServerCallback();
            _bluetoothServer         = _bluetoothManager.OpenGattServer(ctx, _bluettothServerCallback);

            var service = new BluetoothGattService(UUID.FromString("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"),
                                                   GattServiceType.Primary);

            _characteristic = new BluetoothGattCharacteristic(UUID.FromString("d8de624e-140f-4a22-8594-e2216b84a5f2"), GattProperty.Read | GattProperty.Notify | GattProperty.Write, GattPermission.Read | GattPermission.Write);

            service.AddCharacteristic(_characteristic);
            _bluetoothServer.AddService(service);

            SensorSpeed speed = SensorSpeed.UI;

            OrientationSensor.Start(speed);
            OrientationSensor.ReadingChanged += OrientationSensor_ReadingChanged;

            _bluettothServerCallback.CharacteristicReadRequest += _bluettothServerCallback_CharacteristicReadRequest;
            Console.WriteLine("Server created!");

            BluetoothLeAdvertiser myBluetoothLeAdvertiser = _bluetoothAdapter.BluetoothLeAdvertiser;

            var builder = new AdvertiseSettings.Builder();

            builder.SetAdvertiseMode(AdvertiseMode.LowLatency);
            builder.SetConnectable(true);
            builder.SetTimeout(0);
            builder.SetTxPowerLevel(AdvertiseTx.PowerHigh);
            AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
            dataBuilder.SetIncludeDeviceName(true);
            dataBuilder.SetIncludeTxPowerLevel(true);

            myBluetoothLeAdvertiser.StartAdvertising(builder.Build(), dataBuilder.Build(), new BleAdvertiseCallback());
        }
예제 #7
0
        public BleServer(Context ctx)
        {
            _bluetoothManager = (BluetoothManager)ctx.GetSystemService(Context.BluetoothService);
            _bluetoothAdapter = _bluetoothManager.Adapter;

            _bluettothServerCallback = new BleGattServerCallback();
            _bluetoothServer = _bluetoothManager.OpenGattServer(ctx, _bluettothServerCallback);

            var service = new BluetoothGattService(UUID.FromString("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"),
                GattServiceType.Primary);
            _characteristic = new BluetoothGattCharacteristic(UUID.FromString("d8de624e-140f-4a22-8594-e2216b84a5f2"), GattProperty.Read | GattProperty.Notify | GattProperty.Write, GattPermission.Read | GattPermission.Write);
            _characteristic.AddDescriptor(new BluetoothGattDescriptor(UUID.FromString("28765900-7498-4bd4-aa9e-46c4a4fb7b07"),
                    GattDescriptorPermission.Read | GattDescriptorPermission.Write));

            service.AddCharacteristic(_characteristic);

            _bluetoothServer.AddService(service);

            _bluettothServerCallback.CharacteristicReadRequest += _bluettothServerCallback_CharacteristicReadRequest;
            _bluettothServerCallback.NotificationSent += _bluettothServerCallback_NotificationSent;

            Console.WriteLine("Server created!");

            BluetoothLeAdvertiser myBluetoothLeAdvertiser = _bluetoothAdapter.BluetoothLeAdvertiser;

            var builder = new AdvertiseSettings.Builder();
            builder.SetAdvertiseMode(AdvertiseMode.LowLatency);
            builder.SetConnectable(true);
            builder.SetTimeout(0);
            builder.SetTxPowerLevel(AdvertiseTx.PowerHigh);
            AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
            dataBuilder.SetIncludeDeviceName(true);
            //dataBuilder.AddServiceUuid(ParcelUuid.FromString("ffe0ecd2-3d16-4f8d-90de-e89e7fc396a5"));
            dataBuilder.SetIncludeTxPowerLevel(true);

            myBluetoothLeAdvertiser.StartAdvertising(builder.Build(), dataBuilder.Build(), new BleAdvertiseCallback());
        }
예제 #8
0
        // use predefined Bluetooth SIG definitions for well know characteristics on UWP- Windows project.
        //public static Guid ManufacturerName = GattCharacteristicUuids.ManufacturerNameString;

        public BleServer(Context ctx)
        {
            _isRunning = false;

            try
            {
                _bluetoothManager = (BluetoothManager)ctx.GetSystemService(Context.BluetoothService);

                _bluetoothAdapter = _bluetoothManager.Adapter;

                _bluettothServerCallback = new BleGattServerCallback();
                _bluetoothServer         = _bluetoothManager.OpenGattServer(ctx, _bluettothServerCallback);

                var service = new BluetoothGattService(UUID.FromString(App.ServiceId), GattServiceType.Primary);

                //_characteristicDataExchange = new BluetoothGattCharacteristic(UUID.FromString(App.DataExchange), GattProperty.Read | GattProperty.Notify | GattProperty.Write, GattPermission.Read | GattPermission.Write);
                _characteristicInitData = new BluetoothGattCharacteristic(UUID.FromString(App.InitData), GattProperty.Read | GattProperty.Notify | GattProperty.Write, GattPermission.Read | GattPermission.Write);

                _characteristicFirmwareVersion  = new BluetoothGattCharacteristic(UUID.FromString(App.FirmwareVersion), GattProperty.Read, GattPermission.Read);
                _characteristicDeviceNickname   = new BluetoothGattCharacteristic(UUID.FromString(App.DeviceNickname), GattProperty.Read, GattPermission.Read);
                _descriptorDeviceNickname       = new BluetoothGattDescriptor(UUID.FromString(App.DeviceNicknameDescriptor), GattDescriptorPermission.Read);
                _characteristicDeviceContact    = new BluetoothGattCharacteristic(UUID.FromString(App.DeviceContact), GattProperty.Read, GattPermission.Read);
                _characteristicDeviceInfo       = new BluetoothGattCharacteristic(UUID.FromString(App.DeviceInfo), GattProperty.Read, GattPermission.Read);
                _characteristicInfected         = new BluetoothGattCharacteristic(UUID.FromString(App.IsInfected), GattProperty.Read, GattPermission.Read);
                _characteristicManufacturerName = new BluetoothGattCharacteristic(UUID.FromString(App.ManufacturerName), GattProperty.Read, GattPermission.Read);
                _characteristicMAC = new BluetoothGattCharacteristic(UUID.FromString(App.DeviceMAC), GattProperty.Read, GattPermission.Read);

                //_characteristicDataExchange.SetValue("Data exchange");
                //service.AddCharacteristic(_characteristicDataExchange);

                _characteristicFirmwareVersion.SetValue(App.FirmwareVersionValue);
                service.AddCharacteristic(_characteristicFirmwareVersion);

                _characteristicDeviceNickname.SetValue(App.DeviceNicknameValue);
                service.AddCharacteristic(_characteristicDeviceNickname);

                _characteristicDeviceContact.SetValue(App.DeviceContactValue);
                service.AddCharacteristic(_characteristicDeviceContact);

                _characteristicDeviceInfo.SetValue(App.DeviceInfoValue);
                service.AddCharacteristic(_characteristicDeviceInfo);

                _characteristicMAC.SetValue(App.DeviceMACValue);
                service.AddCharacteristic(_characteristicMAC);

                //_characteristicInitData.SetValue("SPACE - Copyright 2020");
                //service.AddCharacteristic(_characteristicInitData);

                _characteristicInfected.SetValue(App.IsInfectedValue);
                service.AddCharacteristic(_characteristicInfected);

                _characteristicManufacturerName.SetValue(App.ManufacturerNameValue);

                service.AddCharacteristic(_characteristicManufacturerName);

                _bluetoothServer.AddService(service);

                _bluettothServerCallback.CharacteristicReadRequest  += _bluettothServerCallback_CharacteristicReadRequest;
                _bluettothServerCallback.CharacteristicWriteRequest += _bluettothServerCallback_CharacteristicWriteRequest;
                //_bluettothServerCallback.NotificationSent += _bluettothServerCallback_NotificationSent;

                Console.WriteLine("Server created!");

                BluetoothLeAdvertiser myBluetoothLeAdvertiser = _bluetoothAdapter.BluetoothLeAdvertiser;

                var builder = new AdvertiseSettings.Builder();
                builder.SetAdvertiseMode(AdvertiseMode.LowLatency);
                builder.SetConnectable(true);
                builder.SetTimeout(0);
                builder.SetTxPowerLevel(AdvertiseTx.PowerHigh);


                AdvertiseData.Builder dataBuilder = new AdvertiseData.Builder();
                //dataBuilder.SetIncludeDeviceName(false);
                dataBuilder.AddServiceUuid(ParcelUuid.FromString(App.ServiceId));
                dataBuilder.SetIncludeTxPowerLevel(true);
                //byte[] data = Encoding.UTF8.GetBytes(App.ManufacturerNameValue);
                //dataBuilder.AddManufacturerData(0x00E0, data);


                AdvertiseData.Builder dataResponseBuilder = new AdvertiseData.Builder();
                dataResponseBuilder.SetIncludeDeviceName(true);

                //AdvertiseData.Builder dataManufacturerBuilder = new AdvertiseData.Builder();
                //byte[] data = Encoding.UTF8.GetBytes(App.ManufacturerNameValue);
                //dataManufacturerBuilder.AddManufacturerData(49177, data);

                myBluetoothLeAdvertiser.StartAdvertising(builder.Build(), dataBuilder.Build(), dataResponseBuilder.Build(), new BleAdvertiseCallback());

                _isRunning = true;
            }
            catch (System.Exception ex)
            {
            }
        }