All Projects → harry1453 → android-bluetooth-serial

harry1453 / android-bluetooth-serial

Licence: Apache-2.0 license
A library for Android to simplify basic serial communication over Bluetooth, for example when communicating with Arduinos.

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to android-bluetooth-serial

pySerialTransfer
Python package to transfer data in a fast, reliable, and packetized form
Stars: ✭ 78 (-35%)
Mutual labels:  serial, serial-communication, arduinos
BOSCH-GLM-rangefinder
Python script to remote control a BOSCH GLM 100C rangefinder via its Bluetooth serial interface
Stars: ✭ 41 (-65.83%)
Mutual labels:  serial, bluetooth
SerialTransfer
Arduino library to transfer dynamic, packetized data fast and reliably via Serial, I2C, or SPI
Stars: ✭ 273 (+127.5%)
Mutual labels:  serial, serial-communication
Androbd
Android OBD diagnostics with any ELM327 adapter
Stars: ✭ 573 (+377.5%)
Mutual labels:  serial, bluetooth
micronova controller
Allows you to easily control via MQTT any Micronova equiped pellet stove. (MCZ, Extraflame, Laminox, and many others brands!)
Stars: ✭ 30 (-75%)
Mutual labels:  serial, serial-communication
Androidbluetoothlibrary
A Library for easy implementation of Serial Bluetooth Classic and Low Energy on Android. 💙
Stars: ✭ 171 (+42.5%)
Mutual labels:  serial, bluetooth
Node Bluetooth Serial Port
Serial I/O over bluetooth for NodeJS
Stars: ✭ 444 (+270%)
Mutual labels:  serial, bluetooth
Arduino Robust Serial
A simple and robust serial communication protocol. It was designed for Arduino but can be used for other purposes (e.g. bluetooth, sockets). Implementation in C Arduino, C++, Python and Rust.
Stars: ✭ 83 (-30.83%)
Mutual labels:  serial, bluetooth
Johnny Five
JavaScript Robotics and IoT programming framework, developed at Bocoup.
Stars: ✭ 12,498 (+10315%)
Mutual labels:  serial, bluetooth
Web Bluetooth Terminal
Progressive Web Application for serial communication with your own Bluetooth Low Energy (Smart) devices
Stars: ✭ 130 (+8.33%)
Mutual labels:  serial, bluetooth
LibSerialPort.jl
Julia wrapper for the libserialport c library
Stars: ✭ 54 (-55%)
Mutual labels:  serial, serial-communication
Arduino Cmdmessenger
CmdMessenger Communication library for Arduino & .NET
Stars: ✭ 175 (+45.83%)
Mutual labels:  serial, bluetooth
bluetooth-terminal
ES6 class for serial communication with your own Bluetooth Low Energy (Smart) devices
Stars: ✭ 43 (-64.17%)
Mutual labels:  serial, bluetooth
SmartSpin2k
Transform your spin bike into a Smart Trainer!
Stars: ✭ 88 (-26.67%)
Mutual labels:  bluetooth
gba-remote-play
Stream Raspberry Pi games to a GBA via Link Cable
Stars: ✭ 356 (+196.67%)
Mutual labels:  serial
react-native-easybluetooth-classic
⚛ A Library for easy implementation of Serial Bluetooth Classic on React Native (Android Only).
Stars: ✭ 44 (-63.33%)
Mutual labels:  bluetooth
cloudbbq
A Bluetooth to MQTT bridge for the Tenergy Solis Digital Meat Thermometer and other similar devices.
Stars: ✭ 36 (-70%)
Mutual labels:  bluetooth
ble2mqtt
A BLE to MQTT bridge
Stars: ✭ 60 (-50%)
Mutual labels:  bluetooth
gen-cisco
🧨 Generates Cisco scripts based on YAML files
Stars: ✭ 29 (-75.83%)
Mutual labels:  serial
iconsole-android
OpeniConsole connects to an iConsole+ fitness bike head unit over bluetooth.
Stars: ✭ 27 (-77.5%)
Mutual labels:  bluetooth

android-bluetooth-serial

Build Status

A library for Android to simplify basic serial communication over Bluetooth, for example when communicating with Arduinos.

How to include the library

JitPack

Gradle

  • Project level build.gradle
allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}
  • App level build.gradle
dependencies {
    implementation 'com.github.harry1453:android-bluetooth-serial:v1.1'
    
    // RxJava is also required.
    implementation 'io.reactivex.rxjava2:rxjava:2.1.12'
    implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
}

Using the library

Please see the demoApplication directory for a fully-featured demo app.

  1. Declare your BluetoothManager (Make sure to include the library BluetoothManager, not the Android one):
import com.harrysoft.androidbluetoothserial.BluetoothManager;

Your Activity's onCreate():

// Setup our BluetoothManager
BluetoothManager bluetoothManager = BluetoothManager.getInstance();
if (bluetoothManager == null) {
    // Bluetooth unavailable on this device :( tell the user
    Toast.makeText(context, "Bluetooth not available.", Toast.LENGTH_LONG).show(); // Replace context with your context instance.
    finish();
}
  1. Get the list of paired devices:
Collection<BluetoothDevice> pairedDevices = bluetoothManager.getPairedDevices();
for (BluetoothDevice device : pairedDevices) {
    Log.d("My Bluetooth App", "Device name: " + device.getName());
    Log.d("My Bluetooth App", "Device MAC Address: " + device.getAddress());
}
  1. Select a device you want to connect to from the list and fetch its MAC Address.

  2. Connect to the device and send/receive messages:

import com.harrysoft.androidbluetoothserial.BluetoothSerialDevice;
private SimpleBluetoothDeviceInterface deviceInterface;

private void connectDevice(String mac) {
    bluetoothManager.openSerialDevice(mac)
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(this::onConnected, this::onError);
}

private void onConnected(BluetoothSerialDevice connectedDevice) {
    // You are now connected to this device!
    // Here you may want to retain an instance to your device:
    deviceInterface = connectedDevice.toSimpleDeviceInterface();
    
    // Listen to bluetooth events
    deviceInterface.setListeners(this::onMessageReceived, this::onMessageSent, this::onError);
    
    // Let's send a message:
    deviceInterface.sendMessage("Hello world!");
}

private void onMessageSent(String message) {
    // We sent a message! Handle it here.
    Toast.makeText(context, "Sent a message! Message was: " + message, Toast.LENGTH_LONG).show(); // Replace context with your context instance.
}

private void onMessageReceived(String message) {
    // We received a message! Handle it here.
    Toast.makeText(context, "Received a message! Message was: " + message, Toast.LENGTH_LONG).show(); // Replace context with your context instance.
}

private void onError(Throwable error) {
    // Handle the error
}
  1. Disconnect the device:
// Please remember to destroy your instance after closing as it will no longer function!

// Disconnect one device
bluetoothManager.closeDevice(macAddress); // Close by mac
// OR
bluetoothManager.closeDevice(connectedDevice); // Close by device instance
// OR
bluetoothManager.closeDevice(deviceInterface); // Close by interface instance

// Disconnect all devices
bluetoothManager.close();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].