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

QLowEnergyController not working

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 2 Posters 1.2k Views 2 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
    avrik
    wrote on last edited by
    #1

    Hi all!
    I'm trying to get services from my device.

    void BluetoothService::FindDevices() {
        discoveryAgent = new QBluetoothDeviceDiscoveryAgent();
    
        connect(discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo&)), this, SLOT(foundDevice(const QBluetoothDeviceInfo&)));
        connect(discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(deviceScanError(QBluetoothDeviceDiscoveryAgent::Error)));
        connect(discoveryAgent, SIGNAL(finished()), this, SLOT(scanFinished()));
        connect(discoveryAgent, SIGNAL(canceled()), this, SLOT(scanCanseled()));
    
        qWarning() << "\nStart searshing for devices!";
        discoveryAgent->start();
    }
    
    void BluetoothService::foundDevice(const QBluetoothDeviceInfo &info) {
        qWarning() << "Found device: " << info.address() << " " << info.name();
        
        if (info.coreConfigurations() & QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration ) {
            qWarning() << "This device is BLE";
            
            if (info.address().toString() == QString("F8:84:F2:0A:DC:3D")){
                qWarning() << "This is our device!";
                CheckServices(info.address());
            }
        }
    }
    
    void BluetoothService::CheckServices(QBluetoothAddress address) {
        qWarning() << "Discovering services from device: " << address;
        
        m_control = new QLowEnergyController(address, this);
        connect(m_control, SIGNAL(serviceDiscovered(QBluetoothUuid)),
                this, SLOT(serviceDiscovered(QBluetoothUuid)));
        connect(m_control, SIGNAL(discoveryFinished()),
                this, SLOT(serviceScanDone()));
        connect(m_control, SIGNAL(error(QLowEnergyController::Error)),
                this, SLOT(controllerError(QLowEnergyController::Error)));
        connect(m_control, SIGNAL(connected()),
                this, SLOT(deviceConnected()));
        connect(m_control, SIGNAL(disconnected()),
                this, SLOT(deviceDisconnected()));
        
        m_control->connectToDevice();
    }
    
    void BluetoothService::serviceDiscovered(QBluetoothUuid serviceID) {
        qWarning() << "Found service: " << serviceID;
    }
    
    void BluetoothService::serviceScanDone() {
        qWarning() << "Service scan done!";
    }
    
    void BluetoothService::controllerError(QLowEnergyController::Error) {
        qWarning() << "Controller error!";
    }
    
    void BluetoothService::deviceConnected() {
        qWarning() << "Device connected!";
        m_control->discoverServices();
    }
    
    
    void BluetoothService::deviceDisconnected() {
        qWarning() << "Device disconnected!";
    }
    

    And then nothing. Slots doesn't calling.

    Console output:

    Compiled with Qt Version  5.5.0
    
    Start searshing for devices!
    Found device:  "F8:84:F2:0A:DC:3D"   "Test Galaxy S5"
    This device is BLE
    This is our device!
    Discovering services from device:  "F8:84:F2:0A:DC:3D"
    Found device:  "6F:EE:DC:16:3E:99"   "6F-EE-DC-16-3E-99"
    This device is BLE
    Found device:  "90:00:DB:30:FC:38"   "Test Galaxy Tab S "
    This device is BLE
    Scan finished
    Wanna restart? (Y/N): n
    root@edison:~# Hub
    Compiled with Qt Version  5.5.0
    
    Start searshing for devices!
    Found device:  "6F:EE:DC:16:3E:99"   "6F-EE-DC-16-3E-99"
    This device is BLE
    Found device:  "90:00:DB:30:FC:38"   "Test Galaxy Tab S "
    This device is BLE
    Found device:  "F8:84:F2:0A:DC:3D"   "Test Galaxy S5"
    This device is BLE
    This is our device!
    Trying connect to device:  "F8:84:F2:0A:DC:3D"
    
    Bass13200B 1 Reply Last reply
    0
    • A avrik

      Hi all!
      I'm trying to get services from my device.

      void BluetoothService::FindDevices() {
          discoveryAgent = new QBluetoothDeviceDiscoveryAgent();
      
          connect(discoveryAgent, SIGNAL(deviceDiscovered(const QBluetoothDeviceInfo&)), this, SLOT(foundDevice(const QBluetoothDeviceInfo&)));
          connect(discoveryAgent, SIGNAL(error(QBluetoothDeviceDiscoveryAgent::Error)), this, SLOT(deviceScanError(QBluetoothDeviceDiscoveryAgent::Error)));
          connect(discoveryAgent, SIGNAL(finished()), this, SLOT(scanFinished()));
          connect(discoveryAgent, SIGNAL(canceled()), this, SLOT(scanCanseled()));
      
          qWarning() << "\nStart searshing for devices!";
          discoveryAgent->start();
      }
      
      void BluetoothService::foundDevice(const QBluetoothDeviceInfo &info) {
          qWarning() << "Found device: " << info.address() << " " << info.name();
          
          if (info.coreConfigurations() & QBluetoothDeviceInfo::BaseRateAndLowEnergyCoreConfiguration ) {
              qWarning() << "This device is BLE";
              
              if (info.address().toString() == QString("F8:84:F2:0A:DC:3D")){
                  qWarning() << "This is our device!";
                  CheckServices(info.address());
              }
          }
      }
      
      void BluetoothService::CheckServices(QBluetoothAddress address) {
          qWarning() << "Discovering services from device: " << address;
          
          m_control = new QLowEnergyController(address, this);
          connect(m_control, SIGNAL(serviceDiscovered(QBluetoothUuid)),
                  this, SLOT(serviceDiscovered(QBluetoothUuid)));
          connect(m_control, SIGNAL(discoveryFinished()),
                  this, SLOT(serviceScanDone()));
          connect(m_control, SIGNAL(error(QLowEnergyController::Error)),
                  this, SLOT(controllerError(QLowEnergyController::Error)));
          connect(m_control, SIGNAL(connected()),
                  this, SLOT(deviceConnected()));
          connect(m_control, SIGNAL(disconnected()),
                  this, SLOT(deviceDisconnected()));
          
          m_control->connectToDevice();
      }
      
      void BluetoothService::serviceDiscovered(QBluetoothUuid serviceID) {
          qWarning() << "Found service: " << serviceID;
      }
      
      void BluetoothService::serviceScanDone() {
          qWarning() << "Service scan done!";
      }
      
      void BluetoothService::controllerError(QLowEnergyController::Error) {
          qWarning() << "Controller error!";
      }
      
      void BluetoothService::deviceConnected() {
          qWarning() << "Device connected!";
          m_control->discoverServices();
      }
      
      
      void BluetoothService::deviceDisconnected() {
          qWarning() << "Device disconnected!";
      }
      

      And then nothing. Slots doesn't calling.

      Console output:

      Compiled with Qt Version  5.5.0
      
      Start searshing for devices!
      Found device:  "F8:84:F2:0A:DC:3D"   "Test Galaxy S5"
      This device is BLE
      This is our device!
      Discovering services from device:  "F8:84:F2:0A:DC:3D"
      Found device:  "6F:EE:DC:16:3E:99"   "6F-EE-DC-16-3E-99"
      This device is BLE
      Found device:  "90:00:DB:30:FC:38"   "Test Galaxy Tab S "
      This device is BLE
      Scan finished
      Wanna restart? (Y/N): n
      root@edison:~# Hub
      Compiled with Qt Version  5.5.0
      
      Start searshing for devices!
      Found device:  "6F:EE:DC:16:3E:99"   "6F-EE-DC-16-3E-99"
      This device is BLE
      Found device:  "90:00:DB:30:FC:38"   "Test Galaxy Tab S "
      This device is BLE
      Found device:  "F8:84:F2:0A:DC:3D"   "Test Galaxy S5"
      This device is BLE
      This is our device!
      Trying connect to device:  "F8:84:F2:0A:DC:3D"
      
      Bass13200B Offline
      Bass13200B Offline
      Bass13200
      wrote on last edited by
      #2

      @avrik I know this post is 10 months old, anyway it might help:

      I have rather the same approach as yours, with a difference, when you write:
      m_control = new QLowEnergyController(address, this);

      you call QLowEnergyController constructor with a BT address, which you retreived earlier from info.address().

      On my side, I call like this:
      m_control = new QLowEnergyController( info, this );
      passing the whole QBluetoothDeviceInfo instead oh just the address.
      It works for me

      Hope this can help

      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