Skip to content

Latest commit

 

History

History

bluetooth.central

Overview

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.

Flow

Here's the flow of the example:

  1. The mobile is configured to provide the current time service.
  2. The mobile starts advertising.
  3. The example starts scanning.
  4. When the example receives an advertisement, if the advertised name matches the expected one, then it connects to the device.
  5. When the example is connected to the mobile, it discovers the services that the mobile provides.
  6. 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.
  7. When the mobile receives a read request on the current time characteristic, it sends back a read response.
  8. When the example receives a read response on the current time characteristic, it prints the time provided by the mobile.

Requirements

  • 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:

Usage

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.

Mobile App

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 on OK.
  • For step 2:
    • Open the ADVERTISER tab and click on the pencil button.
    • Type Example as device name and click on RENAME.
    • Click on the + button.
    • Click on ADD RECORD and select Complete Local Name.
    • Select Connectable and click on OK.
    • Turn on the new advertiser configuration and click on OK.
  • For step 7:
    • This is done automatically by the mobile app.

Run on simulator

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 the microej 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.

Run on device

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 the microej 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.

Dependencies

All dependencies are retrieved transitively by Gradle.

Source

N/A

Restrictions

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.