Skip to content

BLE GATT Server ask for pairing #13

@GurgenHOVH

Description

@GurgenHOVH

When trying to connect to the server hosted on an Android device, it opens a pairing request on both server and client.

The service and advertising looks like this:

 await BlePeripheral.addService(
        BleService(
          uuid: serviceTicketing,
          primary: true,
          characteristics: [
            BleCharacteristic(
              uuid: characteristicTicketing,
              properties: [
                CharacteristicProperties.write.index,
              ],
              value: null,
              permissions: [AttributePermissions.writeable.index],
            ),
          ],
        ),
      );

      /// set callback for advertising state
      BlePeripheral.setAdvertisingStatusUpdateCallback(
          (bool advertising, String? error) {
        print("AdvertisingStatus: $advertising Error $error");
      });

      BlePeripheral.setWriteRequestCallback(
          (deviceId, characteristicId, offset, value) {
        print(
            "WriteRequest: $deviceId ${String.fromCharCodes(value?.toList() ?? [])} : $offset : $value ");

        final userId = String.fromCharCodes(value?.toList() ?? []);

        if (userId.isNotEmpty) {
          addUserId(userId);
        }

        return null;
      });

      // Start advertising
      await BlePeripheral.startAdvertising(
        services: [serviceTicketing],
        localName: "ticketing",
      );

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions