This API enables serial communication over Bluetooth. It was written for communicating with Arduino.
bluetoothSerial.available(function (numBytes) {
console.log("There are " + numBytes + " available to read.");
});
window.bluetoothSerial.available(function (numBytes) {
console.log("There are " + numBytes + " available to read.");
});
window.bluetoothSerial.available(function (numBytes) {
console.log("There are " + numBytes + " available to read.");
});
(<any>window).bluetoothSerial.available(function (numBytes) {
console.log("There are " + numBytes + " available to read.");
});
window.bluetoothSerial.available(function (numBytes) {
console.log("There are " + numBytes + " available to read.");
});
connect(macAddress_or_uuid: string): Promise<any>
Connect to a Bluetooth device. The function connect takes a MAC address of the remote device.
connectInsecure(macAddress: string): Promise<any>
Function connectInsecure works like connect, but creates an insecure connection to a Bluetooth device.
disconnect(): Promise<any>
Function disconnect disconnects the current connection.
connectInsecure(macAddress: string): Promise<any>
Writes data to the serial port. Data can be an ArrayBuffer, string, array of integers, or a Uint8Array.
Internally string, integer array, and Uint8Array are converted to an ArrayBuffer. String conversion assume 8bit characters.
connectInsecure(macAddress: string): Promise<any>
Gets the number of bytes of data available.
read(delimiter: string): Promise<any>
Reads data from the buffer.
readUntil(delimiter: string): Promise<any>
Reads data from the buffer until it reaches a delimiter.
subscribe(delimiter: string): Promise<any>
Subscribe to be notified when data is received.
unsubscribe(): Promise<any>
Unsubscribe from a subscription.
unsubscribe(): Promise<any>
Subscribe to be notified when data is received.
unsubscribeRawData(): Promise<any>
Subscribe to be notified when data is received.
clear(): Promise<any>
Clears data in the buffer.
isEnabled(): Promise<any>
Reports if bluetooth is enabled.
isConnected(): Promise<any>
Reports the connection status.
readRSSI(): Promise<any>
Reads the RSSI from the connected peripheral.
showBluetoothSettings(): Promise<any>
Show the Bluetooth settings on the device.
enable(): Promise<any>
Enable Bluetooth on the device.
discoverUnpaired(): Promise<ResultDiscoverUnpaired>
Discovers unpaired Bluetooth devices.
The discovery process takes a while to happen. You can register notify callback with setDeviceDiscoveredListener. You may also want to show a progress indicator while waiting for the discover proces to finish.
Calling connect on an unpaired Bluetooth device should begin the pairing process.
setDeviceDiscoveredListener(): Promise<ResultSetDeviceDiscoveredListener>
Register a notify callback function to be called during bluetooth device discovery. For callback to work, discovery process must be started with discoverUnpaired. There can be only one registered callback.
clearDeviceDiscoveredListener(): Promise<any>
Clears notify callback function registered with SetDeviceDiscoveredListener.
setName(newName: string): Promise<any>
Sets the human readable device name that is broadcasted to other devices.
setDiscoverable(discoverableDuration: int): Promise<any>
Makes the device discoverable by other devices.
setDiscoverable takes an int for the number of seconds device should be discoverable. A time of 0 will make it permanently discoverable.
[{ "class": 276, "id": "10:BF:48:CB:00:00", "address": "10:BF:48:CB:00:00", "name": "Nexus 7" }, { "class": 7936, "id": "00:06:66:4D:00:00", "address": "00:06:66:4D:00:00", "name": "RN42" }]
[{ "class": 276, "id": "10:BF:48:CB:00:00", "address": "10:BF:48:CB:00:00", "name": "Nexus 7" }, { "class": 7936, "id": "00:06:66:4D:00:00", "address": "00:06:66:4D:00:00", "name": "RN42" }]
{ "class": 276, "id": "10:BF:48:CB:00:00", "address": "10:BF:48:CB:00:00", "name": "Nexus 7" }