Search in sources :

Example 6 with BluetoothGattService

use of android.bluetooth.BluetoothGattService in project physical-web by google.

the class FatBeaconBroadcastService method initGattServer.

private void initGattServer() {
    mGattServer = mBluetoothManager.openGattServer(this, mGattServerCallback);
    BluetoothGattService service = new BluetoothGattService(UUID.fromString(SERVICE_UUID), BluetoothGattService.SERVICE_TYPE_PRIMARY);
    BluetoothGattCharacteristic webpage = new BluetoothGattCharacteristic(CHARACTERISTIC_WEBPAGE_UUID, BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ);
    service.addCharacteristic(webpage);
    mGattServer.addService(service);
}
Also used : BluetoothGattService(android.bluetooth.BluetoothGattService) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 7 with BluetoothGattService

use of android.bluetooth.BluetoothGattService in project Gadgetbridge by Freeyourgadget.

the class PebbleGATTServer method initialize.

boolean initialize() {
    BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
    mBluetoothGattServer = bluetoothManager.openGattServer(mContext, this);
    if (mBluetoothGattServer == null) {
        return false;
    }
    BluetoothGattService pebbleGATTService = new BluetoothGattService(SERVER_SERVICE, BluetoothGattService.SERVICE_TYPE_PRIMARY);
    pebbleGATTService.addCharacteristic(new BluetoothGattCharacteristic(READ_CHARACTERISTICS, BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ));
    writeCharacteristics = new BluetoothGattCharacteristic(WRITE_CHARACTERISTICS, BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE | BluetoothGattCharacteristic.PROPERTY_NOTIFY, BluetoothGattCharacteristic.PERMISSION_WRITE);
    writeCharacteristics.addDescriptor(new BluetoothGattDescriptor(CHARACTERISTICS_CONFIGURATION_DESCRIPTOR, BluetoothGattDescriptor.PERMISSION_WRITE));
    pebbleGATTService.addCharacteristic(writeCharacteristics);
    mBluetoothGattServer.addService(pebbleGATTService);
    return true;
}
Also used : BluetoothManager(android.bluetooth.BluetoothManager) BluetoothGattService(android.bluetooth.BluetoothGattService) BluetoothGattDescriptor(android.bluetooth.BluetoothGattDescriptor) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 8 with BluetoothGattService

use of android.bluetooth.BluetoothGattService in project Gadgetbridge by Freeyourgadget.

the class AbstractBTLEDeviceSupport method gattServicesDiscovered.

private void gattServicesDiscovered(List<BluetoothGattService> discoveredGattServices) {
    if (discoveredGattServices == null) {
        logger.warn("No gatt services discovered: null!");
        return;
    }
    Set<UUID> supportedServices = getSupportedServices();
    Map<UUID, BluetoothGattCharacteristic> newCharacteristics = new HashMap<>();
    for (BluetoothGattService service : discoveredGattServices) {
        if (supportedServices.contains(service.getUuid())) {
            logger.debug("discovered supported service: " + BleNamesResolver.resolveServiceName(service.getUuid().toString()) + ": " + service.getUuid());
            List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
            if (characteristics == null || characteristics.isEmpty()) {
                logger.warn("Supported LE service " + service.getUuid() + "did not return any characteristics");
                continue;
            }
            HashMap<UUID, BluetoothGattCharacteristic> intmAvailableCharacteristics = new HashMap<>(characteristics.size());
            for (BluetoothGattCharacteristic characteristic : characteristics) {
                intmAvailableCharacteristics.put(characteristic.getUuid(), characteristic);
                logger.info("    characteristic: " + BleNamesResolver.resolveCharacteristicName(characteristic.getUuid().toString()) + ": " + characteristic.getUuid());
            }
            newCharacteristics.putAll(intmAvailableCharacteristics);
            synchronized (characteristicsMonitor) {
                mAvailableCharacteristics = newCharacteristics;
            }
        } else {
            logger.debug("discovered unsupported service: " + BleNamesResolver.resolveServiceName(service.getUuid().toString()) + ": " + service.getUuid());
        }
    }
}
Also used : HashMap(java.util.HashMap) BluetoothGattService(android.bluetooth.BluetoothGattService) UUID(java.util.UUID) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 9 with BluetoothGattService

use of android.bluetooth.BluetoothGattService in project BleLiteLib4android by afunx.

the class MainActivity method tapMe.

private void tapMe() {
    Log.i(TAG, "tapMe()");
    final String bleAddr = "24:0A:C4:00:02:BC";
    final UUID UUID_WIFI_SERVICE = UUID.fromString("0000ffff-0000-1000-8000-00805f9b34fb");
    final UUID UUID_CONFIGURE_CHARACTERISTIC = UUID.fromString("0000ff01-0000-1000-8000-00805f9b34fb");
    final Context context = MainActivity.this;
    final BleGattClientProxy proxy = mProxy;
    new Thread() {

        @Override
        public void run() {
            int count = 0;
            while (!mIsStop) {
                Log.e(TAG, "connect and close count: " + (++count));
                proxy.connect(bleAddr, 20000);
                BluetoothGattService gattService = proxy.discoverService(UUID_WIFI_SERVICE, 5000);
                proxy.requestMtu(64, 2000);
                if (gattService != null) {
                    BluetoothGattCharacteristic characteristic = proxy.discoverCharacteristic(gattService, UUID_CONFIGURE_CHARACTERISTIC);
                    if (characteristic != null) {
                        proxy.writeCharacteristic(characteristic, "ssid:wifi-11".getBytes(), 5000);
                        byte[] msgRead = proxy.readCharacteristic(characteristic, 5000);
                        System.out.println("BH msgRead: " + Arrays.toString(msgRead));
                        BleGattClientProxy.OnCharacteristicNotificationListener listener = new BleGattClientProxy.OnCharacteristicNotificationListener() {

                            @Override
                            public void onCharacteristicNotification(byte[] msg) {
                                System.out.println("BH ********************onCharacteristicNotification() msg: " + Arrays.toString(msg));
                            }
                        };
                        proxy.registerCharacteristicNotification(characteristic, listener);
                        proxy.writeCharacteristic(characteristic, "passwd:sumof1+1=2".getBytes(), 5000);
                        proxy.writeCharacteristic(characteristic, "confirm:".getBytes(), 5000);
                        proxy.unregisterCharacteristicNotification(characteristic.getUuid());
                        System.out.println("BH ********************Sleep 20 seconds********************");
                        try {
                            Thread.sleep(20 * 1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                        mIsStop = true;
                    }
                }
                proxy.close();
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }.start();
}
Also used : Context(android.content.Context) BleGattClientProxy(com.afunx.ble.blelitelib.proxy.BleGattClientProxy) BluetoothGattService(android.bluetooth.BluetoothGattService) UUID(java.util.UUID) BluetoothGattCharacteristic(android.bluetooth.BluetoothGattCharacteristic)

Example 10 with BluetoothGattService

use of android.bluetooth.BluetoothGattService in project BleSensorTag by StevenRudenko.

the class BleServicesAdapter method getGroupView.

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {
    final GroupViewHolder holder;
    if (convertView == null) {
        holder = new GroupViewHolder();
        convertView = inflater.inflate(R.layout.li_service, parent, false);
        holder.name = (TextView) convertView.findViewById(R.id.name);
        holder.uuid = (TextView) convertView.findViewById(R.id.uuid);
        convertView.setTag(holder);
    } else {
        holder = (GroupViewHolder) convertView.getTag();
    }
    final BluetoothGattService item = getGroup(groupPosition);
    final String serviceName;
    final String uuid;
    if (item == null) {
        serviceName = "Unknown";
        uuid = null;
    } else if (def == null) {
        serviceName = "Unknown";
        uuid = item.getUuid().toString();
    } else {
        uuid = item.getUuid().toString();
        final Sensor sensor = def.getSensor(uuid);
        if (sensor != null) {
            serviceName = sensor.getName();
        } else {
            serviceName = "Unknown";
        }
    }
    holder.name.setText(serviceName);
    holder.uuid.setText(uuid);
    return convertView;
}
Also used : BluetoothGattService(android.bluetooth.BluetoothGattService) TiPeriodicalSensor(sample.ble.sensortag.sensor.ti.TiPeriodicalSensor) Sensor(com.chimeraiot.android.ble.sensor.Sensor) BaseSensor(sample.ble.sensortag.sensor.BaseSensor)

Aggregations

BluetoothGattService (android.bluetooth.BluetoothGattService)10 BluetoothGattCharacteristic (android.bluetooth.BluetoothGattCharacteristic)8 BluetoothGattDescriptor (android.bluetooth.BluetoothGattDescriptor)3 HashMap (java.util.HashMap)3 BluetoothGatt (android.bluetooth.BluetoothGatt)2 UUID (java.util.UUID)2 BluetoothAdapter (android.bluetooth.BluetoothAdapter)1 BluetoothDevice (android.bluetooth.BluetoothDevice)1 BluetoothManager (android.bluetooth.BluetoothManager)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 SimpleExpandableListAdapter (android.widget.SimpleExpandableListAdapter)1 BleGattClientProxy (com.afunx.ble.blelitelib.proxy.BleGattClientProxy)1 Sensor (com.chimeraiot.android.ble.sensor.Sensor)1 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 BaseSensor (sample.ble.sensortag.sensor.BaseSensor)1