Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. App for bluetooth scanning
Forum Update on Monday, May 27th 2025

App for bluetooth scanning

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 6 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.
  • A Offline
    A Offline
    AndreaFurlani
    wrote on last edited by
    #1

    Hello, I am developing an app that once connected to a device (call it box), it gets a list of all the objects (lamps, doors and other sensors) and send them commands like "switch off the light 1".
    I want to know if from an external application is possible to get all the connected objects to the box or there are security issues.
    The external app doesn't connect directly to the objects but must send the command to the box.
    I was thinking to use signals.
    Thank you for the help.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      Are you reimplementing an equivalent to Apple's HomeKit ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        @SGaist said in App for bluetooth scanning:

        Apple's HomeKit

        I am currently working on similar project - controlling a radio transceiver.
        I am basically replacing "wired control" with wireless - bluetooth.
        The key is - the controlled device - "the box" - has to be enabled to allow such control. In my case the control is limited by design. I can "set the frequency", but I cannot "key the transmitter" .
        You could call that "device security".
        AT present the box is expecting plain serial communication commands , pretty much "modem style". These commands could be encoded to provide for additional bluetooth security .
        Is that what you are referring to as "security"?'' It would probably be interesting to code , but given limited range of bluetooth and me controlling only single bluetooth device , I would consider that little of overkill .

        BUT - be aware that Qt / Linux implementation of bluetooth has a MAJOR issue - there is no option to scan / inquiry for physically present devices only.
        There is a database of past devices and I have not found Qt/Linux way to delete non-existent devices from such database. .
        I had to go back to HCI to clear this database.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          AndreaFurlani
          wrote on last edited by
          #4

          Thank you both for the replies.
          @SGaist Yes I'm working on something similar.

          @AnneRanch as security I mean something like "you cannot see information of the devices or a devices list on an external app because Bluetooth doesn't allow thing like this"

          I was thinking something like this:

          1. The app scan for devices to connect and I can choose the box (easy part, lot of examples in Qt);
          2. Once connected, the box send to the app a list of all the actually connected devices which will be displayed in the app;
          3. In the app I can select a device and a new window will appears with the buttons "on" and "off";
          4. Once I select one of the options, the app will send to the box a signal "device x, command y";
          5. The box reads the command and send it to the device that will perform the designated action
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Thanks for the clear picture.

            Can you explain what you were thinking to do with regards to the use of signals ?

            It seems that you have a pretty well defined API so I think you'll have a controller that will be responsible for the communication with the "hub" device. Is it so ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            A 1 Reply Last reply
            0
            • A Offline
              A Offline
              Anonymous_Banned275
              wrote on last edited by
              #6

              @AndreaFurlani said in App for bluetooth scanning:

              The app scan for devices to connect and I can choose the box (easy part, lot of examples in Qt);
              I am not sure what you call "the box" .
              I do not want to be pedantic - but IMHO "home brew " terminology can became unnecessary issue in the long run.
              During my , still ongoing , development I found that it is helpful to call "local (bluetooth) device " the one connected to your controller and "remote (bluetooth) device ".
              I have found that "client /server" is little misleading when "two way communication" is involved , so does "home ".

              Again - not that important when it is all "under one roof " .

              I am not sure that monitoring the bluetooth "raw data" is best way to limit the function of the "remote device". But I came from "telecommunication background " and I always view the communication payload as "transparent ". In my case - I cannot "key-up" the remote transmitter device so I won't even attempt to send anything close to such command.

              1 Reply Last reply
              0
              • SGaistS SGaist

                Thanks for the clear picture.

                Can you explain what you were thinking to do with regards to the use of signals ?

                It seems that you have a pretty well defined API so I think you'll have a controller that will be responsible for the communication with the "hub" device. Is it so ?

                A Offline
                A Offline
                AndreaFurlani
                wrote on last edited by
                #7

                @SGaist Since I'm quite new in Qt and specially in bluetooth, I have no idea on how my app can ask to the box for the list of devices, so my idea was like:

                1- the app send a request signal to the box
                2- the box answer back by sending a list containing all the devices connected
                3- once the user has selected what to do with a device, the app send back a variable containing the device and the action to perform

                A 1 Reply Last reply
                0
                • A AndreaFurlani

                  @SGaist Since I'm quite new in Qt and specially in bluetooth, I have no idea on how my app can ask to the box for the list of devices, so my idea was like:

                  1- the app send a request signal to the box
                  2- the box answer back by sending a list containing all the devices connected
                  3- once the user has selected what to do with a device, the app send back a variable containing the device and the action to perform

                  A Offline
                  A Offline
                  Anonymous_Banned275
                  wrote on last edited by Anonymous_Banned275
                  #8

                  @AndreaFurlani said in App for bluetooth scanning:

                  @SGaist Since I'm quite new in Qt and specially in bluetooth, I have no idea on how my app can ask to the box for the list of devices, so my idea was like:

                  1- the app send a request signal to the box
                  2- the box answer back by sending a list containing all the devices connected
                  3- once the user has selected what to do with a device, the app send back a variable containing the device and the action to perform

                  OK, I am still missing something here .
                  Again , from my background :
                  in general - "communication" has three basic parts and for simplicity it is defined as communication in one direction only.

                  sender -> communication media ->receiver
                  or
                  source communication media sink / load

                  Where is your "box" in this scheme ? Does look like this ?

                  sender communication media (bluetooth) "receiver BOX sender " communication media ( actual media ?) receiver

                  where "BOX sender" is actually multiple senders ?

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    Your box needs to have a protocol established.

                    See the exchanging data between devices part of the Bluetooth chapter in Qt's documentation.

                    You'll then have to establish a clear protocol for your "service".

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    A A 2 Replies Last reply
                    0
                    • SGaistS SGaist

                      Your box needs to have a protocol established.

                      See the exchanging data between devices part of the Bluetooth chapter in Qt's documentation.

                      You'll then have to establish a clear protocol for your "service".

                      A Offline
                      A Offline
                      Anonymous_Banned275
                      wrote on last edited by
                      #10

                      @SGaist said in App for bluetooth scanning:

                      Your box needs to have a protocol established.

                      See the exchanging data between devices part of the Bluetooth chapter in Qt's documentation.

                      You'll then have to establish a clear protocol for your "service".

                      Very helpful post .
                      Since I started by using btscanner example I was wondering why my "remote bluetooth device " is "identified as "SPP" . Now I have an answer.
                      After I get this "inquiry" mess cleaned - up my next step is indeed using "chat "...

                      1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Your box needs to have a protocol established.

                        See the exchanging data between devices part of the Bluetooth chapter in Qt's documentation.

                        You'll then have to establish a clear protocol for your "service".

                        A Offline
                        A Offline
                        AndreaFurlani
                        wrote on last edited by
                        #11

                        @SGaist Thank you very much. I'll try to read it and make some tries.

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

                          Hello again, I returned Here since I'm still stuck. In this moment I'm trying to create a new bluetooth service (in the box code), where I'll ask for creating an retrieve a list of all connected devices (and I still have not idea on how to do it, I saw this in the documentation, maybe could be useful).
                          So in this way I can create another service (on the app code) where once retrieved the list will associate to a device a command (and again I still have not idea on how to do it) and send it back to the box to execute it.
                          Any idea on how I can do it?
                          Thank you again for all the help.

                          A 1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            Something is not clear, what will run on that box ?

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            A 1 Reply Last reply
                            0
                            • A AndreaFurlani

                              Hello again, I returned Here since I'm still stuck. In this moment I'm trying to create a new bluetooth service (in the box code), where I'll ask for creating an retrieve a list of all connected devices (and I still have not idea on how to do it, I saw this in the documentation, maybe could be useful).
                              So in this way I can create another service (on the app code) where once retrieved the list will associate to a device a command (and again I still have not idea on how to do it) and send it back to the box to execute it.
                              Any idea on how I can do it?
                              Thank you again for all the help.

                              A Offline
                              A Offline
                              Anonymous_Banned275
                              wrote on last edited by Anonymous_Banned275
                              #14

                              @AndreaFurlani I would suggest to take a look at examples. Start with "qtconnectivity" - btscanner.
                              It does the basics - scans for nearby bluetooth devices etc.
                              However it is scarcely documented - in code - and assumes some knowledge about bluetooth.
                              From my experience - do not assume that your "local bluetooth device " is enabled to be used to scan for "remote bluetooth devices".
                              I have two with different dongles with different "class of service" and the scan results are NOT the same.

                              Same for "remote bluetooth device" - my powered "remote device " with serial USB to bluetooth adapter" can be "found" , my powered remote "boom box" has to be activated to be found.
                              Beware of running active operating system "bluetooth manager" software - it actually over-rides , takes precedence, of SOME of your code.

                              A 1 Reply Last reply
                              0
                              • SGaistS SGaist

                                Something is not clear, what will run on that box ?

                                A Offline
                                A Offline
                                AndreaFurlani
                                wrote on last edited by
                                #15

                                @SGaist The box is connected to some lights and sensors via zigbee or bluetooth. I need a list of all the connected devices to the box

                                SGaistS 1 Reply Last reply
                                0
                                • A Anonymous_Banned275

                                  @AndreaFurlani I would suggest to take a look at examples. Start with "qtconnectivity" - btscanner.
                                  It does the basics - scans for nearby bluetooth devices etc.
                                  However it is scarcely documented - in code - and assumes some knowledge about bluetooth.
                                  From my experience - do not assume that your "local bluetooth device " is enabled to be used to scan for "remote bluetooth devices".
                                  I have two with different dongles with different "class of service" and the scan results are NOT the same.

                                  Same for "remote bluetooth device" - my powered "remote device " with serial USB to bluetooth adapter" can be "found" , my powered remote "boom box" has to be activated to be found.
                                  Beware of running active operating system "bluetooth manager" software - it actually over-rides , takes precedence, of SOME of your code.

                                  A Offline
                                  A Offline
                                  AndreaFurlani
                                  wrote on last edited by
                                  #16

                                  @AnneRanch thank you for the answer. I already watched all the bluetooth examples in Qt creator but no one of them is useful to understand how to create a new service and in particular how to do the things I need.

                                  A 1 Reply Last reply
                                  0
                                  • A AndreaFurlani

                                    @AnneRanch thank you for the answer. I already watched all the bluetooth examples in Qt creator but no one of them is useful to understand how to create a new service and in particular how to do the things I need.

                                    A Offline
                                    A Offline
                                    Anonymous_Banned275
                                    wrote on last edited by
                                    #17

                                    @AndreaFurlani said in App for bluetooth scanning:

                                    how to create a new service

                                    Since bluetooth devices have "class of service" be careful using the term.
                                    I am still unclear about your overall task . I think I asked for simple hardware picture before .
                                    Let me make analogy with my project
                                    local bt device (PC) -> bluetooth media communication path -> remote bt device (radio )

                                    one on my "services" would be - set the radio frequency

                                    so "my box - radio " would turn on correct frequency and display it on build-in LCD

                                    Are you attempting to do similar tasks via your box ?

                                    1 Reply Last reply
                                    0
                                    • A AndreaFurlani

                                      @SGaist The box is connected to some lights and sensors via zigbee or bluetooth. I need a list of all the connected devices to the box

                                      SGaistS Offline
                                      SGaistS Offline
                                      SGaist
                                      Lifetime Qt Champion
                                      wrote on last edited by
                                      #18

                                      @AndreaFurlani said in App for bluetooth scanning:

                                      @SGaist The box is connected to some lights and sensors via zigbee or bluetooth. I need a list of all the connected devices to the box

                                      Hence my question what software runs on that box ?

                                      Interested in AI ? www.idiap.ch
                                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                      1 Reply Last reply
                                      0
                                      • A Offline
                                        A Offline
                                        AndreaFurlani
                                        wrote on last edited by
                                        #19

                                        Hello I'm back again. I made some progress in writing my code. Now the box starts the advertising without problem.
                                        Here's the code:

                                        void bluetoothDevice::start(bool debugMode, bool protocolDebug)
                                        {
                                            //Personalized Service for connected bluetooth devices list
                                        
                                            static const QLatin1String serviceUuid("11223344-5566-7788-99aa-bbccddeeff00");
                                            //static const QLatin1String writeListUuid("11223344-5566-7788-99aa-bbccddeeff11");
                                            static const QLatin1String readListUuid("11223344-5566-7788-99aa-bbccddeeff11");
                                        
                                            // [Advertising Data]
                                                QLowEnergyAdvertisingData advertisingData;
                                                advertisingData.setDiscoverability(QLowEnergyAdvertisingData::DiscoverabilityGeneral);
                                                advertisingData.setIncludePowerLevel(true);
                                                advertisingData.setLocalName("BOX");
                                                advertisingData.setServices(QList<QBluetoothUuid>() << QBluetoothUuid(serviceUuid));
                                        
                                            // [Service Data]
                                                QLowEnergyCharacteristicData readList;
                                        
                                                readList.setUuid(QBluetoothUuid(readListUuid));
                                                readList.setProperties(QLowEnergyCharacteristic::Read);
                                                const QLowEnergyDescriptorData clientConfig(QBluetoothUuid::CharacteristicUserDescription,QByteArray(2, 0));
                                                readList.addDescriptor(clientConfig);
                                        
                                        
                                                //writeList.setUuid(QBluetoothUuid(writeListUuid));
                                                //writeList.setProperties(QLowEnergyCharacteristic::Write);
                                        
                                        
                                                QLowEnergyServiceData serviceData;
                                                serviceData.setType(QLowEnergyServiceData::ServiceTypePrimary);
                                                serviceData.setUuid(QBluetoothUuid(serviceUuid));
                                                serviceData.addCharacteristic(readList);
                                                //serviceData.addCharacteristic(writeList);
                                        
                                        
                                            // [Start Advertising]
                                        
                                                leController.reset(QLowEnergyController::createPeripheral());
                                                service_list.reset(leController->addService(serviceData));
                                                leController->startAdvertising(QLowEnergyAdvertisingParameters(), advertisingData,advertisingData);
                                        
                                        
                                            qCDebug(BLELog) << " Start BLE backend [...] ";
                                        
                                            ConnectionHandler connectionHandler;
                                            DeviceHandler m_deviceHandler;
                                        
                                        
                                            // TODO! Restore debug options.
                                            GenericDeviceIf::start(debugMode, protocolDebug);
                                        
                                            // Initialize reachable state to unreachable.
                                            DataModel::getInstance()->setDeviceCategoryReachable(_category, false);
                                        
                                            _endpoints = DataModel::getInstance() ->getEndpointsListByCategory(dataBaseClasses::ENDPOINT_CATEGORY_BLE);
                                        
                                            m_deviceHandler.setDevice(nullptr);
                                            qDeleteAll(devices);
                                            devices.clear();
                                        
                                            emit devicesChanged();
                                        
                                            qCDebug(BLELog) << "Scanning for devices...";
                                        
                                            discoveryAgent->start(QBluetoothDeviceDiscoveryAgent::LowEnergyMethod);
                                        
                                            emit scanningChanged();
                                        
                                            // [Retrieving the list of devices]
                                        
                                                characteristic = service_list->characteristic(QBluetoothUuid(readListUuid));
                                        
                                                for (const auto &e: _endpoints){
                                                    L.append(QString(e->getMapping()).toUtf8());
                                                }
                                        
                                                if (L.empty())
                                                    qCDebug(BLELog) << "No endpoints loaded in the list";
                                        
                                                for (const auto &list: L) {
                                                    service_list -> writeCharacteristic(characteristic, list) ;
                                                }
                                        
                                        
                                        }
                                        

                                        In this way I am able to connect to the BOX using an external BLE scanner app on my phone and once connected I would like to see the content of "list".
                                        With this code the problem is that I can see only the last MAC address in the list, how can I see the complete content?

                                        1 Reply Last reply
                                        0
                                        • H Offline
                                          H Offline
                                          Habanvee
                                          wrote on last edited by Habanvee
                                          #20

                                          I have been using Bluetooth LE Explorer.
                                          But my Bluetooth is not turning on on windows 10 for 2 days any help.

                                          Updated: Glad found the solution here for Bluetooth turning on issue.

                                          jsulmJ 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