Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

BasicAirData/BluetoothHelper

A Bluetooth Java Class for Android.
Offered byBasicAirData - Open and free DIY air data instrumentation and telemetry

Description

This Java Class implements an easy message-based Bluetooth wireless communication layer between anAndroid device (the client) and aMicrocontroller (the server).
Using this class you can Connect, Disconnect, Send String messages, Receive String messages via Listener (best way) or by explicit polling, automatically reconnect and check the status of your Bluetooth connection in a simple and thread-safe way.

The library is compatible with android 4.0 (API 14) and newer.

Here in this repo (in the Arduino/BluetoothHelperExample folder) you can also find a very simple example (around 100 lines of code, including comments) that shows how to use it.
You can find a complete implementation of this library in BasicAirDataAir Data Bridge.

For further information about this library and its usage you can readthis article.

Dependencies

Use Gradle

dependencies {    implementation'eu.basicairdata:bluetoothhelper:1.0.5'}

Or Maven

<dependency>    <groupId>eu.basicairdata</groupId>    <artifactId>bluetoothhelper</artifactId>    <version>1.0.5</version>    <type>pom</type></dependency>

Getting started

Setup

  • Add Bluetooth permissions to your AndroidManifest.xml:
<uses-permission android:name ="android.permission.BLUETOOTH_ADMIN"/><uses-permission android:name ="android.permission.BLUETOOTH"/>
  • Declare a new BluetoothHelper instance into your activity:
BluetoothHelpermBluetoothHelper =newBluetoothHelper();
  • Setup a BluetoothHelperListener to receive the messages and the changes of the connection status:
mBluetoothHelper.setBluetoothHelperListener(newBluetoothHelper.BluetoothHelperListener() {@OverridepublicvoidonBluetoothHelperMessageReceived(BluetoothHelperbluetoothhelper,finalStringmessage) {// Do something with the message received// runOnUiThread(new Runnable() {//     @Override//     public void run() {//         // Update your UI//     }// });    }@OverridepublicvoidonBluetoothHelperConnectionStateChanged(BluetoothHelperbluetoothhelper,booleanisConnected) {// Do something, depending on the new connection status    }});

Common Usage

mBluetoothHelper.Connect(mBluetoothDevice);
  • As alternative, connect to a BluetoothDevice directly using its Device Name:
mBluetoothHelper.Connect("HC-05");
  • Send a message:
mBluetoothHelper.SendMessage("Hello World");
  • Check the connection status:
mBluetoothHelper.isConnected();
  • Disconnect:
mBluetoothHelper.Disconnect();

For further information you can read the fullBluetoothHelper API Documentation.

This repository contains

  • Android/BluetoothHelper.class = The Helper Class for Android;

The repo includes also a very simple but fully functional example, that shows how to use the helper class:

  • Android/BluetoothHelperExample/ = Example app for Android - around 100 lines of code, including comments - that controls 2 leds (one ON/OFF using a button and one in PWM using a slider);
  • Arduino/BluetoothHelperExample/ = The sketch for Arduino; this example (ready to be uploaded on Arduino 2009) is made to communicate with the example app;
  • doc/ = The related documentation. The folder includes the API documentation of the Class and the electrical scheme of the microcontroller circuit, showing one of the possible hardware configurations (Arduino 2009 + BlueSMIRF Gold);

Reference documents

Code of conduct

Contributing Information

Repository License


[8]ページ先頭

©2009-2025 Movatter.jp