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

App for bluetooth scanning

Scheduled Pinned Locked Moved Unsolved General and Desktop
22 Posts 6 Posters 1.9k 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 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
                            • H Habanvee

                              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 Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #21

                              @Habanvee In what way is your question related to Qt?
                              You should rather ask in a Windows forum.

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • M Offline
                                M Offline
                                melissa321
                                wrote on last edited by
                                #22

                                I have been using BLE suite this app has a primary scanner view option that detects all the available devices using the Android operating system.

                                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