pebblebee-bluetooth-web-sdk
v1.0.6
Published
Tools to connect and manage bluetooth devices
Downloads
4
Readme
pebblebee-bluetooth-web-sdk
This project provides a set of functions and tools to simplify the use of the web bluetooth api to connect and manage Pebblebee device
Important notes
In order for the API to work, it has to be used on web site using HTTPS. It won't work on HTTP
To connect to a device an User gesture required, like a button or click
it has to be used on a browser that supports the Web bluetooth api
https://developer.mozilla.org/en-US/docs/Web/API/Web_Bluetooth_API
Functions
bluetoothAvailable()
Returns a boolean that represents if bluetooth is available for the browser
response
{
//in case of error it will be false
btAvailable: boolean
error: boolean,
message: string
}
connectToDeviceByMac(macAddress, deviceDisconnectedCallback)
This function will the search devices dialog of the OS, onces the user selects one, it will return the select device object (BluetoothDevice).
Params
//used to filter the results that show in the connection dialog.
//hexadecimal, valid formats XXXXXXXXXXXX XX:XX:XX:XX:XX:XX XX-XX-XX-XX-XX-XX
macAddress: string
//This function will be invoque in case the device disconnects
deviceDisconnectedCallback: function () => void
response
{
device: BluetoothDevice | undefined,
error: boolean,
message: string
}
getBatteryPercentage(device)
This function connect to the device battery service and parse the battery level into a percentage.
Params
//The device that the action is perfomed on
device: BluetoothDevice
response
{
//if there is and error this will be 0
batteryPercentage: number,
error: boolean,
message: string
}
buzz(device)
This function will connect to the device and send a "buzz" command to it
Params
//The device that the action is perfomed on
device: BluetoothDevice;
response
{
error: boolean,
message: string
}
stopBuzz(device)
This function will connect to the device and send a "stop buzzing" command to it
Params
//The device that the action is perfomed on
device: BluetoothDevice
response
{
error: boolean,
message: string
}