2

I'm developing an app with BLE features. My server (Peripheral) detect that some clients are connected to my server. I notify them by sending some server's information then after that the client receive those informations he send client's informations.

Server

// Inside BluetoothGattServerCallback I receive the client, add him then try to send data to him
@Override
public void onDescriptorWriteRequest(BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor, boolean preparedWrite, boolean responseNeeded, int offset, byte[] value) {
super.onDescriptorWriteRequest(device, requestId, descriptor, preparedWrite, responseNeeded, offset, value);

    addDevice(device);
    mHandlerBLE.post(() -> sendInfoServer(device));
}

private void sendInfoServer(BluetoothDevice device) {
    Random r = new Random();
    int nbr = r.nextInt(9999 - 1) + 1;

    JSONObject json = new JSONObject();
    json.put("ID", nbr + "");
    json.put("pic", "totootototototot");
    json.put("cover", "tututututututu");
    json.put("type", "VIP");
    json.put("address", "totoland 4th street");
    json.put("name", "Welcome Toto");

    byte[] data = StringUtils.bytesFromString(json.toString());
    notifyCharacteristic(data, CHARAC_CONNECTION_UUID, device);

    }

private void notifyCharacteristic(byte[] value, UUID uuid, BluetoothDevice device) {
        mHandlerBLE.post(() -> {

            BluetoothGattService service = mGattServer.getService(SERVICE_UUID);
            BluetoothGattCharacteristic characteristic = service.getCharacteristic(uuid);

            characteristic.setValue(value);
            characteristic.addDescriptor(CHARAC_DESCRIPTOR);

            mGattServer.notifyCharacteristicChanged(device, characteristic, false);

        });
    }

My question is : Is it possible to NOTIFY (server to client) more than 20 bytes ? (notifyCharacteristicChanged)

I saw so many code about to split data into chunk and then send it with mBluetoothGatt.writeCharacteristic(characteristic); in a loop.

So I did the same on server side with mGattServer.notifyCharacteristicChanged(device, characteristic, false); but I failed somewhere (so I removed it)

More information (useless maybe) :

Android client to iOS server : OK

iOS client to iOS server : OK

Android client to Android server : OK only if I request MTU on client side but I don't want to.

iOS client to Android server : NOT OK

Xtazer
  • 161
  • 3
  • 14

0 Answers0