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. QT BLE 4.0 Peripheral Role Full Tutorial or Example

QT BLE 4.0 Peripheral Role Full Tutorial or Example

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.0k 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.
  • B Offline
    B Offline
    Buguito
    wrote on last edited by Buguito
    #1

    Hi guys,
    I've succesfully developed a client (a.k.a central role) with QT Bluetooth LE SDK to work against some electronics of my own. But now, i need to implement the Peripheral Role with QT and my custom GATT Profile

    So far, i've outlined a very small service that will allow to read and write the WPA Config for Linux (to setup the WiFi connection of a Raspberry Pi) using Bluetooth Developer Studio. I've followed the example at the docs to setup discovery of this service.

    bool BluetoothServer::initialize(std::string mac) {
    
      Logger::addLine("BluetoothServer","Initializing with MAC Address: "+mac);
    
      // Set mac address
      macAddress = mac;
    
      // Set BaseStation Bluetooth Address
      QBluetoothAddress address(QString::fromUtf8(macAddress.c_str()));
    
      // Create Local Device
      localDevice = new QBluetoothLocalDevice(address);
      if (!localDevice->isValid()) {
        Logger::addLine("BluetoothServer","Local Bluetooh device not available. Aborting");
        return false;
      }
    
      // Turn Bluetooth on
      localDevice->powerOn();
    
      // Make it visible to others
      localDevice->setHostMode(QBluetoothLocalDevice::HostDiscoverable);
    
      QLowEnergyCharacteristicData charDataNetworkSSID;
      charDataNetworkSSID.setUuid(QBluetoothUuid(QString("{2A9669DE-9AA3-4304-8E06-B122DBC5991B}")));
      charDataNetworkSSID.setValue(QByteArray(""));
      charDataNetworkSSID.setProperties(QLowEnergyCharacteristic::Read | QLowEnergyCharacteristic::WriteNoResponse);
    
      QLowEnergyCharacteristicData charDataPSK;
      charDataPSK.setUuid(QBluetoothUuid(QString("{2A963AB9-9AA3-4304-8E06-B122DBC5991B}")));
      charDataPSK.setValue(QByteArray(""));
      charDataPSK.setProperties(QLowEnergyCharacteristic::Read | QLowEnergyCharacteristic::WriteNoResponse);
    
      QLowEnergyServiceData serviceData;
      serviceData.setUuid(QBluetoothUuid(QString("{2A960000-9AA3-4304-8E06-B122DBC5991B}")));
      serviceData.setType(QLowEnergyServiceData::ServiceTypePrimary);
      serviceData.addCharacteristic(charDataNetworkSSID);
      serviceData.addCharacteristic(charDataPSK);
    
      if (!serviceData.isValid())
        Logger::addLine("BluetoothServer","LE ServiceData is NOT Valid");
    
      QList<QBluetoothUuid> servicesList;// = QList<QBluetoothUuid>();
      servicesList << QBluetoothUuid(QString("{2A960000-9AA3-4304-8E06-B122DBC5991B}"));
    
      QLowEnergyAdvertisingData advertisingData;
      advertisingData.setDiscoverability(QLowEnergyAdvertisingData::DiscoverabilityGeneral);
      advertisingData.setIncludePowerLevel(false);
      advertisingData.setLocalName("GSense");
      advertisingData.setServices(servicesList);
      lowEnergyController = QLowEnergyController::createPeripheral();
      lowEnergyService = lowEnergyController->addService(serviceData);
      lowEnergyController->startAdvertising(QLowEnergyAdvertisingParameters(), advertisingData, advertisingData);
    
      Logger::addLine("BluetoothServer","LE Service ready and awaiting connections");
    
      return true;
    }
    

    So, it's advertised. Though, when i use a BLE Scanner from an Android Cellphone and connect to it, it says "Discovering Services" and it does not show up my custom service . It only shows the Generic Attribute, bla bla.

    So the question is, do you guys have a working example as how to get my service discovered and also provide the callbacks to read and write to my Characteristics?. I'll keep trying with the documentation looking up the QLowEnergyService class and so on, but you might have a properly documented example for the Peripheral Role from start to end.

    The doc at: http://doc.qt.io/qt-5/qtbluetooth-le-overview.html just addresses the Advertisement of a custom GATT and the examples at http://doc.qt.io/qt-5/qtexamplesandtutorials.html only fully develops the Central Role AFAIK.

    Thanks in advance.

    Alan

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

      Hi,

      I'd recommend bringing this to the interest mailing list. You'll find there Qt's developers/maintainers. This forum is more user oriented.

      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
      • S Offline
        S Offline
        SherifOmran
        wrote on last edited by
        #3

        @Buguito
        I am trying to do a similar project, did you reach some result to this issue?

        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