bt
The bt object allows you to check if Bluetooth is fitted; set, monitor, or retrieve the current BLE advertisements; scan for Bluetooth devices; and trigger connection to, and disconnection from, another device.
bt IDL
enum BtCentralEventType {
'advertising-report',
'device-found',
'device-lost'
};
interface BtCentralAdvertisingReportEvent {
attribute String adapter_path;
attribute String device_address;
attribute int rssi;
attribute Array<byte> data;
};
interface BtCentralDeviceFoundEvent {
attribute String adapter_path;
attribute String address;
attribute String alias;
[optional] attribute String name;
[optional] attribute int rssi;
[optional] attribute int tx_power;
[optional] attribute Array<String> uuids;
[optional] attribute Array<byte> advertising_flags;
[optional] attribute Array<Array<int, Array<byte>>> manufacturer_data;
[optional] attribute Map<String, Array<byte>> service_data;
};
interface BtCentralDeviceLostEvent {
attribute String adapter_path;
attribute String address;
};
typedef (BtCentralAdvertisingReportEvent | BtCentralDeviceFoundEvent | BtCentralDeviceLostEvent) BtCentralEvent;
callback BtCentralEventCallback = void (BtCentralEvent event);
interface BtCentral {
Promise<Array<Adapter>> getAdapters();
Promise<void> scan(optional ScanParameters);
Promise<void> stopScan();
void addEventListener(BtCentralEventType type, BtCentralEventCallback callback);
void removeEventListener(BtCentralEventType type, BtCentralEventCallback callback);
};
interface Adapter {
attribute String name;
attribute bool powered;
};
interface ScanParameters {
attribute bool advertisingReports;
};
Object Creation
To create a bt object, first load the brightsign/bt
module using the require()
method. Then create an instance of the bt class.
var btClass = require("@brightsign/bt");
var bt = new btClass();
BtCentralAdvertisingReportEvent
adapter_path
String required: The adapter that the advertising device belongs todevice_address
String required: The identifier for a remote advertising devicerssi
int required: The signal strength of the device when an advertisement is reporteddata
Array<byte> required: Advertisement data
BtCentralDeviceFoundEvent
Indicates if a Bluetooth device is found during scanning
adapter_path
String required: The adapter that the advertising device belongs toaddress
String required: The unique Bluetooth address of the devicealias
String required: An alternate name for the remote devicename
String optional: The name of the Bluetooth devicerssi
int optional: The signal strength of the devicetx_power
int optional: The transmitted power level of the deviceuuids
Array<String> optional: UUID stringsadvertising_flags
Array<byte> optional: The flags used for advertisingmanufacturer_data
Array<Array<int, Array<byte>>> optional: The manufacturer specific advertisement data keyed by manufacturer idservice_data
Map<String, Array<byte>> optional: The service advertisement data keyed by UUID
BtCentralDeviceLostEvent
This is used to report when a Bluetooth device is lost.
adapter_path
String required: The adapter that the advertising device belongs toaddress
String required: The unique Bluetooth address of the device
BtCentral
Use this interface to perform actions on Bluetooth streaming connections.
getAdapters()
Promise<Array<Adapter>> getAdapters()
Returns an array of adapter identity strings. The number of elements in the array is the number of Bluetooth adapters fitted.
scan()
Promise<void> scan(optional ScanParameters)
Reports new Bluetooth devices as they are discovered. It is also possible to monitor raw advertising reports.
ScanParameters
optional:
stopScan()
Promise<void> stopScan()
Stops scanning and reporting new Bluetooth devices
addEventListener
addEventListener(BtCentralEventType type, BtCentralEventCallback callback)
This event is raised when the Bluetooth status changes. Use this method to listen for this event. See JavaScript Event Handling for more information.
removeEventListener
removeEventListener(BtCentralEventType type, BtCentralEventCallback callback)
Use this method to remove an event listener. See JavaScript Event Handling for more information.
Adapter
In BOS versions below 9.1.21 and below 9.0.198, this returns an array of adapter identity strings. The number of elements in the array is the number of Bluetooth adapters fitted.
In BOS versions above 9.1.21 and 9.0.198, this returns an array of adapter objects.
name
String:powered
bool: Whether or not the adapter is powered on
ScanParameters
This interface contains information about a scanned Bluetooth streaming device:
advertisingReports
bool: Whether or not scanning for advertisements is active.