mardi 21 avril 2015

Is it possible to use more than one uuid when using bluetooth device discovery in qt creator?

I'm programming a small qml app for android where I use the bluetoothdiscoverymodel in qt creator. I can already search for bluetoothdevices, see them in a listview and choose them to send some data(for examlple a picture). When I use a uuid, I can only find a device with that special uuid. That's clear so far. But is is possible to combine those two searches. At first I want to make a general search to find all devices around me. One of those devices I want to make to my default device and save this anywhere, my app connects automatically to, when it has been found. But in addition to this it should also search for other devices.

Below you see my code for the discovery, using a uuid.

Thanks for your help!


BluetoothDiscoveryModel {
            id: btModel
            discoveryMode: BluetoothDiscoveryModel.MinimalServiceDiscovery
            uuidFilter: "e8e10f95-1a70-4b27-9ccf-d03972367ccc"

            onErrorChanged: {
                if (error == BluetoothDiscoveryModel.NoError)
                if (error == BluetoothDiscoveryModel.PoweredOffError)
                {titleLabel.text = "Bluetooth turned off";
                    console.log("Please turn bluetooth on!")}
                    titleLabel.text = "Cannot find devices";

            onServiceDiscovered: {
                serviceFound = true
                console.log("Found new service " + service.deviceAddress + " " + service.deviceName + " " + service.serviceName);
                console.log("Connecting to Bluetooth server " + service.deviceName)
        BluetoothSocket {
            id: socket
            connected: true
            onSocketStateChanged: {
                console.log("Connected to Bluetooth server")
            onStringDataChanged: {
                console.log("Received data: ")
                var data = remoteDeviceName + ": " + socket.stringData;
                data = data.substring(0, data.indexOf('\n'))

Aucun commentaire:

Enregistrer un commentaire