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!

model:

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

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

            onServiceDiscovered: {
                if(serviceFound)
                    return
                serviceFound = true
                console.log("Found new service " + service.deviceAddress + " " + service.deviceName + " " + service.serviceName);
                console.log("Connecting to Bluetooth server " + service.deviceName)
                socket.setService(service)
            }
        }
        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