This application provides an implementation example of a Central device using the Bluetooth API.
It is designed to be used with a mobile acting as the Peripheral device.
Here's the flow of the example:
- The mobile is configured to provide the current time service.
- The mobile starts advertising.
- The example starts scanning.
- When the example receives an advertisement, if the advertised name matches the expected one, then it connects to the device.
- When the example is connected to the mobile, it discovers the services that the mobile provides.
- When the example discovers a service, if the service UUID matches the current time service UUID, then it sends a read request on the current time characteristic.
- When the mobile receives a read request on the current time characteristic, it sends back a read response.
- When the example receives a read response on the current time characteristic, it prints the time provided by the mobile.
- MICROEJ SDK 6.
- A VEE Port that contains:
- EDC-1.3 or higher.
- BON-1.4 or higher.
- BLUETOOTH-2.2 or higher.
This example has been tested on:
- Android Studio with MicroEJ plugin for Android Studio 0.1.2.
- Espressif ESP32-S3 VEE Port 2.3.1.
By default, the sample does not load VEE Port and thus it cannot be built for a device nor ran on the simulator.
Refer to the Select a VEE Port documentation for more information.
We recommend using the nRF Connect app on Android to act as the Peripheral device. Here are the instructions to complete the mobile-side steps of the flow with this app:
- For step 1:
- Make sure that Bluetooth is enabled and that the necessary permissions are granted to the mobile app.
- Click on the hamburger button and select
Configure GATT server
. - In the list of configurations, click on the
+
button. - Type anything as configuration name and click on
OK
. - Click on
ADD SERVICE
. - Select
Current Time service
as server configuration and click onOK
.
- For step 2:
- Open the
ADVERTISER
tab and click on the pencil button. - Type
Example
as device name and click onRENAME
. - Click on the
+
button. - Click on
ADD RECORD
and selectComplete Local Name
. - Select
Connectable
and click onOK
. - Turn on the new advertiser configuration and click on
OK
.
- Open the
- For step 7:
- This is done automatically by the mobile app.
In Android Studio:
- Open the Gradle tool window by clicking on the elephant icon on the right side,
- Expand the
Tasks
list, - From the
Tasks
list, expand themicroej
list, - Double-click on
runOnSimulator
, - The application starts, the traces are visible in the Run view.
Alternative ways to run in simulation are described in the Run on Simulator documentation.
Make sure to properly setup the VEE Port environment before going further. Refer to the VEE Port README for more information.
In Android Studio:
- Open the Gradle tool window by clicking on the elephant on the right side,
- Expand the
Tasks
list, - From the
Tasks
list, expand themicroej
list, - Double-Click on
runOnDevice
. - The device is flashed. Use the appropriate tool to retrieve the execution traces.
Alternative ways to run on device are described in the Run on Device documentation.
All dependencies are retrieved transitively by Gradle.
N/A
None.
Copyright 2018-2024 MicroEJ Corp. All rights reserved.
Use of this source code is governed by a BSD-style license that can be found with this software.