Send data between bluetooth devices using a serial like interface
npm install bionic-bt-serial
npx cap sync
addListener(PluginEvents, ...)
addListener('discoveryState', ...)
addListener('discovered', ...)
addListener('rawData', ...)
addListener('connected', ...)
addListener('connectionFailed', ...)
addListener('connectionLost', ...)
getBondedDevices()
startListening(...)
stopListening()
isListening()
connect(...)
isConnected(...)
getConnectedDevices()
disconnect(...)
disconnectAll()
write(...)
isEnabled()
enableAdapter()
disableAdapter()
showBluetoothSettings()
startDiscovery(...)
cancelDiscovery()
setName(...)
getName()
setDiscoverable(...)
- Interfaces
- Type Aliases
- Enums
addListener(eventName: PluginEvents, callback: EventCallback) => Promise<PluginListenerHandle>
Param | Type |
---|---|
eventName |
PluginEvents |
callback |
EventCallback |
Returns: Promise<PluginListenerHandle>
addListener(eventName: 'discoveryState', callback: (result: { starting?: boolean; completed?: boolean; }) => void) => Promise<PluginListenerHandle>
Param | Type |
---|---|
eventName |
'discoveryState' |
callback |
(result: { starting?: boolean; completed?: boolean; }) => void |
Returns: Promise<PluginListenerHandle>
addListener(eventName: 'discovered', callback: (result: BTDevice) => void) => Promise<PluginListenerHandle>
Param | Type |
---|---|
eventName |
'discovered' |
callback |
(result: BTDevice) => void |
Returns: Promise<PluginListenerHandle>
addListener(eventName: 'rawData', callback: (result: RawDataResult) => void) => Promise<PluginListenerHandle>
Param | Type |
---|---|
eventName |
'rawData' |
callback |
(result: RawDataResult) => void |
Returns: Promise<PluginListenerHandle>
addListener(eventName: 'connected', callback: (result: BTDevice) => void) => Promise<PluginListenerHandle>
Param | Type |
---|---|
eventName |
'connected' |
callback |
(result: BTDevice) => void |
Returns: Promise<PluginListenerHandle>
addListener(eventName: 'connectionFailed', callback: (result: BTDevice) => void) => Promise<PluginListenerHandle>
Param | Type |
---|---|
eventName |
'connectionFailed' |
callback |
(result: BTDevice) => void |
Returns: Promise<PluginListenerHandle>
addListener(eventName: 'connectionLost', callback: (result: BTDevice) => void) => Promise<PluginListenerHandle>
Param | Type |
---|---|
eventName |
'connectionLost' |
callback |
(result: BTDevice) => void |
Returns: Promise<PluginListenerHandle>
getBondedDevices() => Promise<{ result: BTDevice[]; }>
Gets a list of the bonded (paired) devices.
Returns: Promise<{ result: BTDevice[]; }>
startListening(_options: {}, callback: ListenCallback) => Promise<void>
Start listening for incoming connections
Param | Type |
---|---|
_options |
{} |
callback |
ListenCallback |
stopListening() => Promise<void>
Stops listening for incoming connections.
isListening() => Promise<{ result: boolean; }>
True if listening for an accepting incoming connections. A device acting as a server should be listening.
Returns: Promise<{ result: boolean; }>
connect(options: { macAddress: string; }) => Promise<void>
Connect to another device acting as a server that is in listening mode. Should already be paired?
Param | Type |
---|---|
options |
{ macAddress: string; } |
isConnected(options: { macAddress: string; }) => Promise<{ result: boolean; }>
True if there is an active connection to the provided macAddress false otherwise.
Param | Type |
---|---|
options |
{ macAddress: string; } |
Returns: Promise<{ result: boolean; }>
getConnectedDevices() => Promise<{ result: BTDevice[]; }>
Gets a list of the connected devices.
Returns: Promise<{ result: BTDevice[]; }>
disconnect(options: { macAddress: string; }) => Promise<{ result: boolean; }>
Disconnects specified connection.
Param | Type |
---|---|
options |
{ macAddress: string; } |
Returns: Promise<{ result: boolean; }>
disconnectAll() => Promise<void>
Disconnects all connections (incomming and outgoing).
write(options: { macAddress: string; data: number[]; }) => Promise<{ result: boolean; }>
Write data to specified macAddress
Param | Type |
---|---|
options |
{ macAddress: string; data: number[]; } |
Returns: Promise<{ result: boolean; }>
isEnabled() => Promise<{ result: boolean; }>
True if device has bluetooth enabled, false otherwise
Returns: Promise<{ result: boolean; }>
enableAdapter() => Promise<void>
Prompt the user to enable bluetooth. Resolved if bluetooth is enabled, rejects otherwise.
disableAdapter() => Promise<void>
Prompt the user to enable bluetooth. Resolved if bluetooth is enabled, rejects otherwise.
showBluetoothSettings() => Promise<void>
Open the bluetooth settings screen for the user.
startDiscovery(_options: {}, callback: DiscoveryCallback) => Promise<void>
Starts discovery process, sends info about found devices to the callback. Scans for about 12 seconds.
Param | Type |
---|---|
_options |
{} |
callback |
DiscoveryCallback |
cancelDiscovery() => Promise<void>
Stops any running discovery process.
setName(options: { name: string; }) => Promise<void>
Sets the name of the bluetooth adapter. Name is what paired devices will see when they connect.
Param | Type |
---|---|
options |
{ name: string; } |
getName() => Promise<{ result: string; }>
Gets the name of the bluetooth adapter.
Returns: Promise<{ result: string; }>
setDiscoverable(options: { durationSec?: number; }) => Promise<void>
Ensure bluetooth is enabled and the device is discoverable to remote scanners. Default durationSec is 120 is not provided. Max is 300 seconds.
Param | Type |
---|---|
options |
{ durationSec?: number; } |
Prop | Type |
---|---|
remove |
() => Promise<void> |
(info: any, err?: any): void
{name:string, macAddress:string, class:number}
{bytes:number[], from:BTDevice}
(device: BTDevice, err?: any): void
(device: BTDevice, err?: any): void
Members | Value |
---|---|
discovered |
"discovered" |
discoveryState |
"discoveryState" |
rawData |
"rawData" |
connected |
"connected" |
connectionFailed |
"connectionFailed" |
connectionLost |
"connectionLost" |