Bluetooth LE Mock

Overview

To run a MicroEJ Application that uses the Bluetooth LE Foundation Library (ej.api.bluetooth) on MicroEJ Simulator, a Bluetooth LE mock controller must be set up first:

Bluetooth-mock-controller

The Bluetooth LE mock controller is a hardware mock of the Bluetooth LE library. It means the Simulator uses a real Bluetooth LE device to scan other devices, advertise, discover services, connect, pair, etc… This design enables testing of apps in a real-world environment.

The Bluetooth LE mock controller implementation is provided for the ESP32-DevKitC board reference. Other implementations or sources can be provided on request.

Requirements

Usage

To simulate a Bluetooth LE application, follow these three steps:

  • Set up the controller
  • Set up the network configuration
  • Run the application on the Simulator

If your are facing any issues, check the Troubleshooting section.

Controller Setup

To set up the controller, follow these steps:

  • Plug-in the ESP32-DevKitC board to your computer,
  • Find the associated COM port,
  • In the flash tool:
    • select the chip “ESP32 DownloadTool”
    • browse for the firmware file
    • set the offset to 0x000000
    • set the COM port
    • set the baudrate to 921 600
    • start the flash download

With the flash download tool from Espressif, you should end with something similar to this :

Bluetooth LE Flash Download Tool Configuration

Bluetooth LE Flash Download Tool Configuration

Network Setup

To configure the network:

  1. Connect your computer to the Wi-Fi network “BLE-Mock-Controller-[hexa device id]” mounted by the controller.

  2. Open a browser and connect to http://192.168.4.1/ to access the Wi-Fi setup interface :

    wifi-setup-interface

  3. Select the desired network and provide the required information if asked. If an error occurs during the connection, retry this step.

  4. In case the device is successfully connected to the desired network, the web page should looks like this:

    wifi-setup-last-screen

    Additionally, the serial output of the device shows connection status.

  5. Connect your computer back to this network : your computer and the controller must be in the same network.

Simulation

It is possible to run the Simulator as many times as necessary using the same setup. Also, rebooting the controller will automatically set up the network with the saved configuration.

The IP address of the controller is available in the logs :

controller-ip

Before running your Bluetooth LE application on the Simulator, in the Run configuration panel, set the simulation mode to “Controller (over net)” and configure the Bluetooth LE mock settings.

Bluetooth LE Mock Configuration

Bluetooth LE Mock Configuration

Launching the application on the Simulator will restore the controller to its initial state (the BLE adapter is disabled).

Troubleshooting

Network Setup Errors

I can’t find the “BLE-Mock-Controller-[hexa device id]” access point

The signal of this Wi-Fi access point may be weaker than the surrounding access points. Try to reduce the distance between the controller and your computer; and rescan. If it’s not possible, try using a smartphone instead (only a browser will be required to set up the network configuration).

I want to override the network configuration

If the Wi-Fi credentials are not valid anymore, the controller restarts the network setup phase. Yet, in case the credentials are valid but you want to change them, erase the flash and reflash the firmware.

Simulation Errors

Error during the simulation : mock could not connect to controller

This error means the mock process (Simulator) could not initialize the connection with the controller. Please check that the device is connected to the network (see logs in the serial port output) and that your computer is in the same network.