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. Bluetooth Device Discovery
Forum Updated to NodeBB v4.3 + New Features

Bluetooth Device Discovery

Scheduled Pinned Locked Moved Solved Mobile and Embedded
12 Posts 5 Posters 2.8k Views 3 Watching
  • 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.
  • A Offline
    A Offline
    admkrk
    wrote on last edited by
    #1

    I have been trying to get device discovery to work for a week or two, on Android, with no luck. I am, basically, using the example from here. The device I am trying to connect to is an HC-05 module. If I use the BT from the phone, it finds it, but my app reports nothing found. I was thinking it might be a runtime permission thing, until earlier when I was talking about my frustration with someone, and ran the app. The app found several devices, I assume other phones. Returning home, I tried to find my device, but nothing turns up, even though the phone still finds it.

    Any ideas as to were to look for a solution to my problem would be greatly appreciated. Considering that it mysteriously worked a couple hours ago, and does not now, I do not know were to begin looking for a solution; phone, code, etc.

    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by sierdzio
      #2

      There are several things that could help you:

      • make sure your phone supports Bluetooth LE (see for example if "nRF Connect for Mobile" app from Play Store can detect and connect to your device)
      • in your AndroidManifest, make sure you request these (coarse location is not a mistake! Modern Androids require it for Bluetooth discovery):
      <uses-permission android:name="android.permission.BLUETOOTH"/>
      <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
      <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
      
      • if your phone is a Nexus device - forget it, their bluetooth module is completely unreliable when used with Qt
      • you may want to add some delay between sending any data to BT device (80-120ms), otherwise some phones start dropping packets
      • if any BLE API call fails - repeat it a few times. Sometimes it works after 2-5 tries

      In general, a word of warning - BLE is a mess on Android. And what's worse, on each platform (Win, mac, iOS, Linux) it works differently :-(

      (Z(:^

      ekkescornerE A 2 Replies Last reply
      2
      • sierdzioS sierdzio

        There are several things that could help you:

        • make sure your phone supports Bluetooth LE (see for example if "nRF Connect for Mobile" app from Play Store can detect and connect to your device)
        • in your AndroidManifest, make sure you request these (coarse location is not a mistake! Modern Androids require it for Bluetooth discovery):
        <uses-permission android:name="android.permission.BLUETOOTH"/>
        <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
        
        • if your phone is a Nexus device - forget it, their bluetooth module is completely unreliable when used with Qt
        • you may want to add some delay between sending any data to BT device (80-120ms), otherwise some phones start dropping packets
        • if any BLE API call fails - repeat it a few times. Sometimes it works after 2-5 tries

        In general, a word of warning - BLE is a mess on Android. And what's worse, on each platform (Win, mac, iOS, Linux) it works differently :-(

        ekkescornerE Offline
        ekkescornerE Offline
        ekkescorner
        Qt Champions 2016
        wrote on last edited by
        #3

        @sierdzio said in Bluetooth Device Discovery:

        In general, a word of warning - BLE is a mess on Android. And what's worse, on each platform (Win, mac, iOS, Linux) it works differently :-(

        I'm using Qt 5.9, 5.10, 5.11 with BT LE on Android and iOS devices without problems:

        • using an Addimat Waiter Lock to LogIn
        • using a BT LE NFC Reader to get NFC functionality for iOS (to get the ID Apple hides) or Android devices without NFC Chip
        • using custom BT LE device to measure mobile network signals

        Also there's my example app "ekke's BT LE Example App" at github https://github.com/ekke/ekkesBTLEexample and also in Apple iOS AppStore and Google Play Store
        perhaps it helps you @admkrk ?

        ekke ... Qt Champion 2016 | 2024 ... mobile business apps
        5.15 --> 6.9 https://t1p.de/ekkeChecklist
        QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

        sierdzioS 1 Reply Last reply
        2
        • sierdzioS sierdzio

          There are several things that could help you:

          • make sure your phone supports Bluetooth LE (see for example if "nRF Connect for Mobile" app from Play Store can detect and connect to your device)
          • in your AndroidManifest, make sure you request these (coarse location is not a mistake! Modern Androids require it for Bluetooth discovery):
          <uses-permission android:name="android.permission.BLUETOOTH"/>
          <uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
          <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
          
          • if your phone is a Nexus device - forget it, their bluetooth module is completely unreliable when used with Qt
          • you may want to add some delay between sending any data to BT device (80-120ms), otherwise some phones start dropping packets
          • if any BLE API call fails - repeat it a few times. Sometimes it works after 2-5 tries

          In general, a word of warning - BLE is a mess on Android. And what's worse, on each platform (Win, mac, iOS, Linux) it works differently :-(

          A Offline
          A Offline
          admkrk
          wrote on last edited by
          #4

          @sierdzio I can only assume the phone supports BLE since the device is discovered by the phone. I tried installing that app and got the same results as I do with mine; no devices found, however. The permissions are set in the manifest, and I was able to discover devices yesterday. I am unsure if it is good or bad that the other app could not find the device either.

          Unfortunately, I only have the one phone, a Samsung, to work with and the one device. I ordered a different device, but that is on a slow boat from China so I will not see it for a while. In the mean time, I will take a look at ekkescorner's code and see if I am overlooking something simple.

          Thanks for the ideas, it is hard to find a solution when I cannot figure out what the problem is.

          1 Reply Last reply
          0
          • ekkescornerE ekkescorner

            @sierdzio said in Bluetooth Device Discovery:

            In general, a word of warning - BLE is a mess on Android. And what's worse, on each platform (Win, mac, iOS, Linux) it works differently :-(

            I'm using Qt 5.9, 5.10, 5.11 with BT LE on Android and iOS devices without problems:

            • using an Addimat Waiter Lock to LogIn
            • using a BT LE NFC Reader to get NFC functionality for iOS (to get the ID Apple hides) or Android devices without NFC Chip
            • using custom BT LE device to measure mobile network signals

            Also there's my example app "ekke's BT LE Example App" at github https://github.com/ekke/ekkesBTLEexample and also in Apple iOS AppStore and Google Play Store
            perhaps it helps you @admkrk ?

            sierdzioS Offline
            sierdzioS Offline
            sierdzio
            Moderators
            wrote on last edited by sierdzio
            #5

            @ekkescorner said in Bluetooth Device Discovery:

            @sierdzio said in Bluetooth Device Discovery:

            In general, a word of warning - BLE is a mess on Android. And what's worse, on each platform (Win, mac, iOS, Linux) it works differently :-(

            I'm using Qt 5.9, 5.10, 5.11 with BT LE on Android and iOS devices without problems

            Well, good for you and good to know :-) On my side, I've run into a myriad of issues:

            • bugs in my code (obviously) :-)
            • bugs in Qt (reported ofc. Some have been fixed already)
            • bugs in operating systems (esp. Windows here, but also some Android implementations)
            • bugs on specific devices (like the mentioned Nexuses, and a few others)
            • bugs on specific devices with specific system and when specific Android SDK was used

            Annoying to the point that I'd be reluctant to do any BLE-related projects in the future. I hope things improve in the future.

            (Z(:^

            ekkescornerE 1 Reply Last reply
            0
            • sierdzioS sierdzio

              @ekkescorner said in Bluetooth Device Discovery:

              @sierdzio said in Bluetooth Device Discovery:

              In general, a word of warning - BLE is a mess on Android. And what's worse, on each platform (Win, mac, iOS, Linux) it works differently :-(

              I'm using Qt 5.9, 5.10, 5.11 with BT LE on Android and iOS devices without problems

              Well, good for you and good to know :-) On my side, I've run into a myriad of issues:

              • bugs in my code (obviously) :-)
              • bugs in Qt (reported ofc. Some have been fixed already)
              • bugs in operating systems (esp. Windows here, but also some Android implementations)
              • bugs on specific devices (like the mentioned Nexuses, and a few others)
              • bugs on specific devices with specific system and when specific Android SDK was used

              Annoying to the point that I'd be reluctant to do any BLE-related projects in the future. I hope things improve in the future.

              ekkescornerE Offline
              ekkescornerE Offline
              ekkescorner
              Qt Champions 2016
              wrote on last edited by
              #6

              @sierdzio oooh. so I was in luck that my BT LE Apps are working well at customer site ;-)

              ekke ... Qt Champion 2016 | 2024 ... mobile business apps
              5.15 --> 6.9 https://t1p.de/ekkeChecklist
              QMake --> CMake https://t1p.de/ekkeCMakeMobileApps

              1 Reply Last reply
              0
              • J.HilkJ Online
                J.HilkJ Online
                J.Hilk
                Moderators
                wrote on last edited by
                #7

                I had some serious issues (with android) with subscribing to BTL services of my target device. Turns out, on android it's a 2 step process on iOS 1 step.
                Took me way to long to get behind that issue.

                But besides that initial challenge, no problems with Qt BTLE, Its a good bit slower on android than on iOS (discovery and connect). But, I learned to accept that as part of android ;-)


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                1
                • A Offline
                  A Offline
                  admkrk
                  wrote on last edited by
                  #8

                  I think I have partially solved my problem. My thorough reading of the example (cough) missed this little bit.

                  Note: It is a prerequisite that the remote devices actively advertise their presence.

                  I did not set up the device, so I do not know if that is actually the problem or not, but I think it is. Since the guy who did has not answered my email, I tried hard coding a simple socket. I got the address from a previous attempt that failed discovery, but did give me an address. That brought up the pairing dialog from my phone, which changed the activity on the device (LED), even if it did not seem to communicate.

                  It might be slow, but at least I am making progress.

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    admkrk
                    wrote on last edited by
                    #9

                    Now I feel really stupid. It helps greatly if you you actually handle the button clicks. It is now working with everything hard coded, so I should not have a problem making it work right.

                    aha_1980A 1 Reply Last reply
                    2
                    • A admkrk

                      Now I feel really stupid. It helps greatly if you you actually handle the button clicks. It is now working with everything hard coded, so I should not have a problem making it work right.

                      aha_1980A Offline
                      aha_1980A Offline
                      aha_1980
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      @admkrk happens to all of us ;)

                      that's why it's helpful to post actual code, most often someone else is able to spot the error.

                      Good luck progressing.

                      Qt has to stay free or it will die.

                      1 Reply Last reply
                      1
                      • A Offline
                        A Offline
                        admkrk
                        wrote on last edited by
                        #11

                        Thanks, I normally would have posted code, but I could not narrow the problem down and posting a huge wall of text would not have helped much, especially since it is pretty much the example I linked. For this last bit, I did not realize the code was an issue until I checked for errors. I did write the functions in C++, I just forgot to call them in the QML.

                        1 Reply Last reply
                        0
                        • A Offline
                          A Offline
                          admkrk
                          wrote on last edited by
                          #12

                          Well my solution was not acceptable. I can understand why, as the user would have to manually enter the address and uuid, I did not care for it either. I ran the desktop example, and it found the device. I made two changes and my copy of the original example is now finding the device. I do not think the first one made a difference, I started the agent without arguments. The one that made a difference was a no brainer once I reread the add device function

                          void Device::addDevice(const QBluetoothDeviceInfo &info)
                          {
                             //if(info.coreConfigurations() & QBluetoothDeviceInfo::LowEnergyCoreConfiguration)
                             //{
                                  DeviceInfo *d = new DeviceInfo(info);
                                  devices.append(d);
                              //}
                          }
                          

                          Anyway, I thought I should update this with the real solution to fixing the example I was using.

                          1 Reply Last reply
                          0

                          • Login

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