|
Veethree D7 SDK
|
All Bluetooth examples use Qt Bluetooth
QML Bluetooth app provides basic bluetooth functionality of scanning for available devices and pairing with them. Key functionality includes:
Build and deploy the app to the D7.
If the D7's bluetooth is powered off, slide the switch indicator to power on. Once powered on, bluetooth cannot be powered off by this app.
If you want to initiate a pairing request to a remote device such as your phone, click on the 'Scan' button and wait for your device to show up. Make sure the remote device is discoverable in device Bluetooth settings before scanning. If pairing with another D7, click on the 'Make discoverable' button.
Once your remote device shows up, click on the 'Pair' button next to it. This will show a 6 digit (0 padded) confirmation code on the D7 and your remote device. Confirm with "Yes" if the code matches on both devices. If the pairing was completed successfully, the button text changes to 'Unpair'.
If you want to initiate a pairing request to the D7 from your phone or any other device, put the D7 in discoverable mode by clicking on the button 'Make discoverable' and run a scan on your remote device. When the D7 is shown on the 'Available Devices' list, click on it to initiate a pairing request. The same 6 digit confirmation popup will be shown. Confirm if correct or deny.
Note: The application can run on windows and linux hosts but may not be fully functional. This app only supports pairing requests from devices that use a numeric comparison pairing. Extend this app to support other pairing methods.
Qt's Bluetooth API supports sending authorized pairing requests through QBluetoothLocalDevice::requestPairing method. However, there are no supported methods to display, confirm and request user to enter passkeys or pin codes. This app handles authorized pairing by creating a BlueZ D-Bus pairing agent. The registered pairing agent handles authorized requests and completes secure pairing. The agent in this app implements only numeric comparison pairing; other methods are unimplemented.
main.cpp has a init_agent_manager method, which registers an agent object as a default agent on org.bluez.AgentManager1 to handle pairing requests. This agent object declared in agent.h must provide all methods of org.BlueZ.Agent interface. The agent class is based on bluez.git simple-agent test. All pairing requests made to the D7 will be handled by this agent while this app is running.
The example code below highlights the main Bluetooth manager class and BlueZ agent object. Please refer to the full example in ~/d7-sdk/examples/gui/qml-bluetooth.
This example shows communication with remote devices over RFCOMM using the Serial Port Profile (SPP). This example lets you exchange messages with multiple devices (other D7(s) running the same example or a PC with Bluetooth support) or directly with a phone. It is based on the official Qt Bluetooth Chat example.
This application can operate in two modes: server and client:
Before building and running this app, make sure your remote devices are paired with the D7 using QML Bluetooth Application.
Build and deploy this app to all the devices you want to connect. Run the app as a server on one designated device. All other devices should run the app in client mode to connect to this server. To set the mode of the app, pass 'server' or 'client' as a command line argument as
OR
From Qt Creator, add the command line argument in Projects > Build & Run > {YOUR-KIT} > Run Settings > Run
To connect to your phone, download the 'Bluetooth Serial Terminal' app. The D7 cannot initiate a connection to the phone because most mobile devices do not advertise a Bluetooth Serial Port Profile service by default and cannot accept incoming requests from the D7. Therefore, the D7 must act as the server, and the phone (running the terminal app) must connect as the client.
Note: The application can run on windows and linux hosts but may not be fully functional.
The example code below highlights common Bluetooth manager class that manages both server and clients. Please refer to the full example in ~/d7-sdk/examples/gui/qml-bluetooth-chat.
Qt Bluetooth Low Energy Server example shows setting up a Generic Attribute Profile (GATT) server that reads analog pin 0 every 3 seconds and sends updates via Bluetooth Low Energy as a GATT Profile Service to a device connected to the D7. This example is based on Qt Bluetooth Low Energy Heart Rate Server. This example demonstrates:
Run the QML Bluetooth Application and pair your phone with the D7
Download the nRF Connect app on your phone (or any app that supports BLE)
To enable advertising on the D7, open a shell to the D7 and run:
Build and deploy this app to D7
Open the nRf connect app, open the 'Scanner' tab and run 'Scan'. Once the advertiser 'D7-IO' appears click the 'Connect' button next to it. This will open a new 'Client' tab
The 'Client' tab should show an 'Unknown Service' with UUID '21be26a3-be26-4795-9884-e5580a5272c7'. Click to expand and explore
Under this service an unknown characteristic with UUID '29081a08-0c73-465c-93d0-508ebdc9975b' and property 'NOTIFY' should be present. Click the 3 downward arrows next to it to subscribe to these notifications and receive live pin readings.
Note: The application can run on windows and linux hosts but may not be fully functional as bluetooth modules on host machines generally do not support BLE peripheral roles.