Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Bond a Low Energy device on Android

    Mobile and Embedded
    bluetooth pairing passkey pin android
    3
    7
    887
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      Darude 0 last edited by Darude 0

      Hi, I'm trying to bond a ble device. I already did this in the past calling QBluetoothLocalDevice::requestPairing, I don't know if this is exactly the right way to do it, but it works with 5.9.
      Now I need to do this operation with QT > 5.12, but this method seems don't work properly. When I call requestPairing method the QBluetoothLocalDevice::PairingError signal occurs immediately. However the OS panel to pair the device is shown but connection is closed and operation is aborted, so no pairing is possible.
      Is my pairing procedure correct? Is there some other way to do it? Is it a bug?

      Gojir4 1 Reply Last reply Reply Quote 0
      • Gojir4
        Gojir4 @Darude 0 last edited by

        @Darude-0 said in Bond a Low Energy device on Android:

        Is my pairing procedure correct?

        What is your procedure ? Can you show the code ?

        Did you add permissions for Bluetooth in the Android manifest ?

        <uses-permission android:name="android.permission.BLUETOOTH"/>
        <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
        
        1 Reply Last reply Reply Quote 0
        • D
          Darude 0 last edited by

          Yes, these permissions are included in manifest. I run same code with QT 5.9.8 and works well.
          Here my code, where "target" is a QBluetoothDeviceInfo* from a list of devices discovered by QBluetoothDeviceDiscoveryAgent

              bleController = new QLowEnergyController(*target);
              myAdapter = new QBluetoothLocalDevice();
              if (myAdapter->pairingStatus(target->address()) != QBluetoothLocalDevice::Paired) {
                      connect(myAdapter,SIGNAL(error(QBluetoothLocalDevice::Error)),
                              this,SLOT(pairingError(QBluetoothLocalDevice::Error)));
                      connect(myAdapter,SIGNAL(pairingFinished(QBluetoothAddress,QBluetoothLocalDevice::Pairing)),
                              this,SLOT(pairingSuccess(QBluetoothAddress,QBluetoothLocalDevice::Pairing)));
                      connect(myAdapter,SIGNAL(hostModeStateChanged(QBluetoothLocalDevice::HostMode)),
                              this, SLOT(modeStateChanged(QBluetoothLocalDevice::HostMode)));
                      myAdapter->requestPairing(target->address(),QBluetoothLocalDevice::Paired);
              }
              else {
                  bleController->connectToDevice();
              }
          
          
          
          Gojir4 1 Reply Last reply Reply Quote 0
          • Gojir4
            Gojir4 @Darude 0 last edited by

            @Darude-0 I didn't notice that it works on Qt 5.9 sorry. Your code seems correct, it seems like a regression if it doesn't work with Qt 5.12.

            1 Reply Last reply Reply Quote 0
            • D
              Darude 0 last edited by

              In my opinion too. I'll try to open an issue

              1 Reply Last reply Reply Quote 1
              • I
                ivk16 last edited by

                Hello Darude!

                Did you resolve this problem?
                I have same it now.

                D 1 Reply Last reply Reply Quote 0
                • D
                  Darude 0 @ivk16 last edited by

                  @ivk16 Yes, take a look here: https://bugreports.qt.io/browse/QTBUG-76565

                  1 Reply Last reply Reply Quote 1
                  • First post
                    Last post