...
Use the BSBtManager object to discover whether any BLE adapters are present and to receive events (for example, when adapters are added or removed). It can also be used to retrieve and modify Bluetooth advertising.
Attributes
The BSBtManager object has the following attribute:
readonly attribute Array adapters
: A list of all available Bluetooth adapters. If this list is empty, there are no adapters present.
Events
Use the onBtEvent()
callback to receive events:
...
Since additional events may be added in the future, your script should have the capacity to handle unrecognized events.
Example
btm.onbtevent = function (ev) { console.log("Event " + ev.name + "; parameter " + ev.parameter); }
Methods
The BSBtManager object has the following methods:
...
The BSBtAdvertisement object represents a single BLE advertisement. It supports advertising data in standard formats or arbitrary custom values. Standard format values can be initialized on construction using a dictionary, but advanced custom fields must be set on the object. Supported modes are described below.
Beacon Format
This mode uses a simple beaconing format:
...
persistent
:(optional) A Boolean value indicating whether the advertisement should persist after every reboot. Beacon advertisements are not persistent by default.
Eddystone-URL Format
This mode uses the Eddystone-URL format:
...
persistent
:(optional) A Boolean value indicating whether the advertisement should persist after every reboot. Eddystone-URL advertisements are not persistent by default.
Eddystone-UID format
This mode uses the Eddystone-UID format:
...
persistent
:(optional) A Boolean value indicating whether the advertisement should persist after every reboot. Eddystone-URL advertisements are not persistent by default.
Custom Format
This mode supports arbitrary custom data. Binary fields are specified as hexadecimal-encoded strings (e.g. the decimal values 12, 128 would be specified as "0C80"). All lists support push()
/pop()
calls and indexing. Duplicate values should not be included.
mode:"custom"
manufacturerData
:(optional) A BSBtManufacturerData object containing the following fields:manufacturer
: An unsigned 16-bit integer valuedata
: Binary data
serviceUUID
:(optional) A list of UUID strings.serviceData
:(optional) A BSBtUUIDData object containing the following fields:uuid
: The UUID stringdata
: Binary data
soliciitUUID
:(optional) A list of UUID strings.connectable:(optional) A Boolean value indicating whether the advertisement should be connectable (for GATT or other services). Advertisements are non-connectable by default.
persistent
:(optional) A Boolean value indicating whether the advertisement should persist after every reboot. Custom advertisements are not persistent by default.
Examples
This script configures a simple advertisement and an Eddystone-URL advertisement and then begins advertising:
...