Java Code Examples for com.welie.blessed.BluetoothPeripheral#setNotify()

The following examples show how to use com.welie.blessed.BluetoothPeripheral#setNotify() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PBluetoothLEClient.java    From PHONK with GNU General Public License v3.0 6 votes vote down vote up
public PBluetoothLEClient readFromCharacteristic(String macAddress, String serviceUUID, String charUUID) {
    BluetoothPeripheral peripheral = central.getPeripheral(macAddress);
    BluetoothGattCharacteristic btChar = peripheral.getCharacteristic(UUID.fromString(serviceUUID), UUID.fromString(charUUID));
    peripheral.readCharacteristic(btChar);
    peripheral.setNotify(btChar, true);
    return this;
}
 
Example 2
Source File: BluetoothHandler.java    From blessed-android with MIT License 4 votes vote down vote up
@Override
public void onServicesDiscovered(BluetoothPeripheral peripheral) {
    Timber.i("discovered services");

    // Request a new connection priority
    peripheral.requestConnectionPriority(CONNECTION_PRIORITY_HIGH);

    // Read manufacturer and model number from the Device Information Service
    if(peripheral.getService(DIS_SERVICE_UUID) != null) {
        peripheral.readCharacteristic(peripheral.getCharacteristic(DIS_SERVICE_UUID, MANUFACTURER_NAME_CHARACTERISTIC_UUID));
        peripheral.readCharacteristic(peripheral.getCharacteristic(DIS_SERVICE_UUID, MODEL_NUMBER_CHARACTERISTIC_UUID));
    }

    // Turn on notifications for Current Time Service
    if(peripheral.getService(CTS_SERVICE_UUID) != null) {
        BluetoothGattCharacteristic currentTimeCharacteristic = peripheral.getCharacteristic(CTS_SERVICE_UUID, CURRENT_TIME_CHARACTERISTIC_UUID);
        peripheral.setNotify(currentTimeCharacteristic, true);

        // If it has the write property we write the current time
        if((currentTimeCharacteristic.getProperties() & PROPERTY_WRITE) > 0) {
            // Write the current time unless it is an Omron device
            if(!(peripheral.getName().contains("BLEsmart_"))) {
                BluetoothBytesParser parser = new BluetoothBytesParser();
                parser.setCurrentTime(Calendar.getInstance());
                peripheral.writeCharacteristic(currentTimeCharacteristic, parser.getValue(), WRITE_TYPE_DEFAULT);
            }
        }
    }

    // Turn on notifications for Battery Service
    if(peripheral.getService(BTS_SERVICE_UUID) != null) {
        peripheral.setNotify(peripheral.getCharacteristic(BTS_SERVICE_UUID, BATTERY_LEVEL_CHARACTERISTIC_UUID), true);
    }

    // Turn on notifications for Blood Pressure Service
    if(peripheral.getService(BLP_SERVICE_UUID) != null) {
        peripheral.setNotify(peripheral.getCharacteristic(BLP_SERVICE_UUID, BLOOD_PRESSURE_MEASUREMENT_CHARACTERISTIC_UUID), true);
    }

    // Turn on notification for Health Thermometer Service
    if(peripheral.getService(HTS_SERVICE_UUID) != null) {
        peripheral.setNotify(peripheral.getCharacteristic(HTS_SERVICE_UUID, TEMPERATURE_MEASUREMENT_CHARACTERISTIC_UUID), true);
    }

    // Turn on notification for Heart Rate  Service
    if(peripheral.getService(HRS_SERVICE_UUID) != null) {
        peripheral.setNotify(peripheral.getCharacteristic(HRS_SERVICE_UUID, HEARTRATE_MEASUREMENT_CHARACTERISTIC_UUID), true);
    }
}