Scan for nearby Bluetooth device using JAVA

June 17, 2022
Scan for nearby Bluetooth device using JAVA

This article is a guide for creating Java applications that can scan for nearby Bluetooth devices. This example project will be helpful to create BLE application easily. Source file is available.

Requirments

  1. BleuIO. (Bluetooth Low Energy USB dongle)
  2. NetBean

About the Project

The script has a COM port settings section. This section shows connected devices to the COM port. Using jSerialComm we get the list of COM ports and show it on a dropdown menu to select.

The connect and disconnect buttons manages the connection of the dongle.

Once we are connected to the BleuIO dongle, we will be able to write AT commands to the dongle using serial port write command.

By clicking on the SCAN button , it will put the dongle into CENTRAL mode, wait for one second and write another AT command (AT+GAPSCAN=3) to scan for nearby Bluetooth devices for three seconds.

The response will be available on the output panel.

The script can be updated as required. For example. If you want to scan for more than three seconds, just update the MainJFrame.java file 271 line.

List of AT commands are available at https://www.bleuio.com/getting_started/docs/commands/

Step 1: Clone the project

Step 2 : Run the project

Connect BleuIO dongle into the computer.

Run the project using NetBean play button.

Alternatively we can open the project using command line interface by going to the root folder of the project and type

java -jar "dist/JavaBleuIO.jar"

The output will look like this.

Lets select a COM port where the BleuIO dongle is connected and click connect. After successful connection, we should be able to click on scan button. The response will be available on output screen.

If we click on scan button again , it will look for nearby devices for three seconds and show the output.

Share this post on :
Follow us on LinkedIn :

Order Now