QT BLE 4.0 Peripheral Role Full Tutorial or Example

  • 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
      // Make it visible to others
      QLowEnergyCharacteristicData charDataNetworkSSID;
      charDataNetworkSSID.setProperties(QLowEnergyCharacteristic::Read | QLowEnergyCharacteristic::WriteNoResponse);
      QLowEnergyCharacteristicData charDataPSK;
      charDataPSK.setProperties(QLowEnergyCharacteristic::Read | QLowEnergyCharacteristic::WriteNoResponse);
      QLowEnergyServiceData serviceData;
      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;
      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.


  • Lifetime Qt Champion


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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.