Jolla and SailfishOS

Bluetooth Discovery

2016-05-29 18:38

Project code is up on Github.

2016-05-29 15:00

The time has come to get more serious about some software development for the Jolla phone.

Since I have been playing around with all the Cypress PSoC BLE stuff lately, let's see what the Jolla has to offer.

To make it short:

Bluetooth in Qt5 on Jolla

Ok, the goal here is not to write a full featured application that uses Bluetooth for something meaningful, but to write a most simple programm that proves the concept on how to access the Bluetooth stack.

While there is a QML type BluetoothDiscoveryModel I did not like it, when I tried to use it. It seems to me, that working directly with the QBluetooth... C++ classes from the Qt libraries to implement the business logic and than just having an adapter for the views implemented in QML, is the much cleaner approach.

So I fired up my Qt Creator 3.5.0 (Sailfish OS), that is based on Qt 5.0.0 and was build on May 4th 2016.

First "Same procedure as every year."

This creates the default template application and configures the project.

Than:

In the final step of preparation:

Now the project looks like this:

And this is the changed main() function:

I did not change anything in BluetoothDiscovery.qml or CoverPage.qml.

In FirstPage.qml I deleted all references to SecondPage.qml and filled some labels with new text..

The more interesting changes though, are:

A scan for new devices is initiated by a user command.

The BluetoothAdapter class is declared in src/BluetoothAdapter.h

as a QObject child.

By registering it as a qmlType in main() in src/BluetoothDiscovery.cpp

We make it accessable for the QML system.

The implementation is strait forward:

If everything works as expected, something like this is the result you should see:

The QBluetoothDeviceDiscoveryAgent object has an internal list of devices it already knows. So it is normal that, if you start the scan again, only devices are reported, that have not been detected in any scan before, since the program was started.

Having the basics in place, how hard can it be to do the more advanced stuff? ;-)