Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Bond a Low Energy device on Android
QtWS25 Last Chance

Bond a Low Energy device on Android

Scheduled Pinned Locked Moved Solved Mobile and Embedded
bluetoothpairingpasskeypinandroid
7 Posts 3 Posters 1.4k Views
  • 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 Offline
    D Offline
    Darude 0
    wrote on 9 Jul 2019, 14:00 last edited by Darude 0 7 Sept 2019, 14:45
    #1

    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?

    G 1 Reply Last reply 9 Jul 2019, 15:45
    0
    • D Darude 0
      9 Jul 2019, 14:00

      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?

      G Offline
      G Offline
      Gojir4
      wrote on 9 Jul 2019, 15:45 last edited by
      #2

      @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
      0
      • D Offline
        D Offline
        Darude 0
        wrote on 10 Jul 2019, 08:51 last edited by
        #3

        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();
            }
        
        
        
        G 1 Reply Last reply 10 Jul 2019, 09:41
        0
        • D Darude 0
          10 Jul 2019, 08:51

          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();
              }
          
          
          
          G Offline
          G Offline
          Gojir4
          wrote on 10 Jul 2019, 09:41 last edited by
          #4

          @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
          0
          • D Offline
            D Offline
            Darude 0
            wrote on 10 Jul 2019, 11:27 last edited by
            #5

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

            1 Reply Last reply
            1
            • I Offline
              I Offline
              ivk16
              wrote on 3 Sept 2020, 17:31 last edited by
              #6

              Hello Darude!

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

              D 1 Reply Last reply 4 Sept 2020, 08:46
              0
              • I ivk16
                3 Sept 2020, 17:31

                Hello Darude!

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

                D Offline
                D Offline
                Darude 0
                wrote on 4 Sept 2020, 08:46 last edited by
                #7

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

                1 Reply Last reply
                1

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved