Need help upgrading to Ionic Framework 4.0? Get assistance with our Enterprise Migration Services EXPLORE NOW

Bluetooth Serial

Improve this doc

This plugin enables serial communication over Bluetooth. It was written for communicating between Android or iOS and an Arduino (not Android to Android or iOS to iOS).

Repo: https://github.com/don/BluetoothSerial

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-bluetooth-serial
    $ npm install --save @ionic-native/bluetooth-serial@4
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { BluetoothSerial } from '@ionic-native/bluetooth-serial';

constructor(private bluetoothSerial: BluetoothSerial) { }


// Write a string
this.bluetoothSerial.write('hello world').then(success, failure);

// Array of int or bytes
this.bluetoothSerial.write([186, 220, 222]).then(success, failure);

// Typed Array
var data = new Uint8Array(4);
data[0] = 0x41;
data[1] = 0x42;
data[2] = 0x43;
data[3] = 0x44;
this.bluetoothSerial.write(data).then(success, failure);

// Array Buffer
this.bluetoothSerial.write(data.buffer).then(success, failure);

Instance Members

connect(macAddress_or_uuid)

Platforms:Android iOS Windows Phone 

Connect to a Bluetooth device

Param Type Details
macAddress_or_uuid string

Identifier of the remote device

Returns: Observable<any> Subscribe to connect, unsubscribe to disconnect.

connectInsecure(macAddress)

Platforms:Android 

Connect insecurely to a Bluetooth device

Param Type Details
macAddress string

Identifier of the remote device

Returns: Observable<any> Subscribe to connect, unsubscribe to disconnect.

disconnect()

Disconnect from the connected device

Returns: Promise<any>

write(data)

Platforms:Android iOS Windows Phone 

Writes data to the serial port

Param Type Details
data any

ArrayBuffer of data

Returns: Promise<any> returns a promise when data has been written

available()

Platforms:Android iOS Windows Phone 

Gets the number of bytes of data available

Returns: Promise<any> returns a promise that contains the available bytes

read()

Platforms:Android iOS Windows Phone 

Reads data from the buffer

Returns: Promise<any> returns a promise with data from the buffer

readUntil(delimiter)

Platforms:Android iOS Windows Phone 

Reads data from the buffer until it reaches a delimiter

Param Type Details
delimiter string

string that you want to search until

Returns: Promise<any> returns a promise

subscribe(delimiter)

Platforms:Android iOS Windows Phone 

Subscribe to be notified when data is received

Param Type Details
delimiter string

the string you want to watch for

Returns: Observable<any> returns an observable.

subscribeRawData()

Platforms:Android iOS Windows Phone 

Subscribe to be notified when data is received

Returns: Observable<any> returns an observable

clear()

Platforms:Android iOS Windows Phone 

Clears data in buffer

Returns: Promise<any> returns a promise when completed

list()

Platforms:Android iOS Windows Phone 

Lists bonded devices

Returns: Promise<any> returns a promise

isEnabled()

Platforms:Android iOS Windows Phone 

Reports if bluetooth is enabled

Returns: Promise<any> returns a promise

isConnected()

Platforms:Android iOS Windows Phone 

Reports the connection status

Returns: Promise<any> returns a promise

readRSSI()

Platforms:Android iOS Windows Phone 

Reads the RSSI from the connected peripheral

Returns: Promise<any> returns a promise

showBluetoothSettings()

Platforms:Android iOS Windows Phone 

Show the Bluetooth settings on the device

Returns: Promise<any> returns a promise

enable()

Platforms:Android iOS Windows Phone 

Enable Bluetooth on the device

Returns: Promise<any> returns a promise

discoverUnpaired()

Platforms:Android iOS Windows Phone 

Discover unpaired devices

Returns: Promise<any> returns a promise

setDeviceDiscoveredListener()

Platforms:Android iOS Windows Phone 

Subscribe to be notified on Bluetooth device discovery. Discovery process must be initiated with the discoverUnpaired function.

Returns: Observable<any> Returns an observable

setName(newName)

Platforms:Android 

Sets the human readable device name that is broadcasted to other devices

Param Type Details
newName string

Desired name of device

setDiscoverable(discoverableDuration)

Platforms:Android 

Makes the device discoverable by other devices

Param Type Details
discoverableDuration number

Desired number of seconds device should be discoverable for

API

Native

General