connect = function (device_id, connectSuccess, connectFailure) { notSupported(); if (connectFailure) connectFailure(); }
...
}, 5000);
*/
## connect
Connect to a peripheral.
ble.connect(device_id, connectSuccess, connectFailure);
### Description
Function `connect` connects to a BLE peripheral. The callback is long running. Success will be called when the connection is successful
. Service and characteristic info will be passed to the success callback in the [peripheral object](#peripheral-data). Failure is
called if the connection fails, or later if the peripheral disconnects. An peripheral object is passed to the failure callback.
[ble.scan](#scan) must be called before calling connect, so the plugin has a list of avaiable peripherals.
...
disconnect = function (device_id, connectSuccess, connectFailure) { notSupported(); if (connectFailure) connectFailure(); }
...
- __connectSuccess__: Success callback function that is invoked when the connection is successful.
- __connectFailure__: Error callback function, invoked when error occurs or the connection disconnects.
## disconnect
Disconnect.
ble.disconnect(device_id, [success], [failure]);
### Description
Function `disconnect` disconnects the selected device.
### Parameters
...
enable = function (success, failure) { notSupported(); if (failure) failure(); }
...
ble.showBluetoothSettings();
## enable
Enable Bluetooth on the device.
ble.enable(success, failure);
### Description
Function `enable` prompts the user to enable Bluetooth.
#### Android
...
isConnected = function (device_id, success, failure) { notSupported(); if (failure) failure(); }
...
- __success__: Success callback function that is invoked when the notification is removed. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
## isConnected
Reports the connection status.
ble.isConnected(device_id, success, failure);
### Description
Function `isConnected` calls the success callback when the peripheral is connected and the failure callback when *not* connected
.
### Parameters
...
isEnabled = function (success, failure) { notSupported(); if (failure) failure(); }
...
}
);
## isEnabled
Reports if bluetooth is enabled.
ble.isEnabled(success, failure);
### Description
Function `isEnabled` calls the success callback when Bluetooth is enabled and the failure callback when Bluetooth is *not* enabled
.
### Parameters
...
read = function (device_id, service_uuid, characteristic_uuid, success, failure) { notSupported(); if (failure) failure(); }
...
- __success__: Success callback function that is invoked when the connection is successful. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
## read
Reads the value of a characteristic.
ble.read(device_id, service_uuid, characteristic_uuid, success, failure);
### Description
Function `read` reads the value of the characteristic.
Raw data is passed from native code to the callback as an [ArrayBuffer](#typed-arrays).
...
readRSSI = function (device_id, success, failure) { notSupported(); if (failure) failure(); }
...
}
);
## readRSSI
Read the RSSI value on the device connection.
ble.readRSSI(device_id, success, failure);
### Description
Samples the RSSI value (a measure of signal strength) on the connection to a bluetooth device. Requires that you have established
a connection before invoking (otherwise an error will be raised).
### Parameters
...
scan = function (services, seconds, success, failure) { notSupported(); if (failure) failure(); }
...
- [ble.enable](#enable)
- [ble.readRSSI](#readrssi)
## scan
Scan and discover BLE peripherals.
ble.scan(services, seconds, success, failure);
### Description
Function `scan` scans for BLE devices. The success callback is called each time a peripheral is discovered. Scanning automatically
stops after the specified number of seconds.
{
"name": "TI SensorTag",
...
showBluetoothSettings = function (success, failure) { notSupported(); if (failure) failure(); }
...
Function `stopStateNotifications` calls the success callback when Bluetooth state notifications have been stopped.
## showBluetoothSettings
Show the Bluetooth settings on the device.
ble.showBluetoothSettings(success, failure);
### Description
Function `showBluetoothSettings` opens the Bluetooth settings for the operating systems.
#### iOS
...
startNotification = function (device_id, service_uuid, characteristic_uuid, success, failure) { notSupported(); if (failure) failure(); }
...
- __success__: Success callback function that is invoked when the connection is successful. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
## startNotification
Register to be notified when the value of a characteristic changes.
ble.startNotification(device_id, service_uuid, characteristic_uuid, success, failure
);
### Description
Function `startNotification` registers a callback that is called *every time* the value of a characteristic changes. This method
handles both `notifications` and `indications`. The success callback is called multiple times.
Raw data is passed from native code to the success callback as an [ArrayBuffer](#typed-arrays).
...
startScan = function (services, success, failure) { notSupported(); if (failure) failure(); }
...
console.log(JSON.stringify(device));
}, failure);
## startScan
Scan and discover BLE peripherals.
ble.startScan(services, success, failure);
### Description
Function `startScan` scans for BLE devices. The success callback is called each time a peripheral is discovered. Scanning will
continue until `stopScan` is called.
{
"name": "TI SensorTag",
...
startScanWithOptions = function (services, options, success, failure) { notSupported(); if (failure) failure(); }
...
function() { console.log("stopScan failed"); }
);
## startScanWithOptions
Scan and discover BLE peripherals, specifying scan options.
ble.startScanWithOptions(services, options, success, failure);
### Description
Function `startScanWithOptions` scans for BLE devices. It operates similarly to the `startScan` function, but allows you to specify
extra options (like allowing duplicate device reports). The success callback is called each time a peripheral is discovered. Scanning
will continue until `stopScan` is called.
{
"name": "TI SensorTag",
...
startStateNotifications = function (success, failure) { notSupported(); if (failure) failure(); }
...
}
);
## startStateNotifications
Registers to be notified when Bluetooth state changes on the device.
ble.startStateNotifications(success, failure);
### Description
Function `startStateNotifications` calls the success callback when the Bluetooth is enabled or disabled on the device.
__States__
...
stopNotifcation = function (device_id, service_uuid, characteristic_uuid, success, failure) { notSupported(); if (failure) failure(); }
n/a
stopScan = function (success, failure) { notSupported(); if (failure) failure(); }
...
);
## stopScan
Stop scanning for BLE peripherals.
ble.stopScan(success, failure);
### Description
Function `stopScan` stops scanning for BLE devices.
### Parameters
...
stopStateNotifications = function (success, failure) { notSupported(); if (failure) failure(); }
...
}
);
## stopStateNotifications
Stops state notifications.
ble.stopStateNotifications(success, failure);
### Description
Function `stopStateNotifications` calls the success callback when Bluetooth state notifications have been stopped.
## showBluetoothSettings
...
write = function (device_id, service_uuid, characteristic_uuid, data, success, failure) { notSupported(); if (failure) failure(); }
...
- __success__: Success callback function that is invoked when the connection is successful. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
## write
Writes data to a characteristic.
ble.write(device_id, service_uuid, characteristic_uuid, data, success, failure);
### Description
Function `write` writes data to a characteristic.
### Parameters
- __device_id__: UUID or MAC address of the peripheral
...
writeWithoutResponse = function (device_id, service_uuid, characteristic_uuid, data, success, failure) { notSupported(); if (failure) failure(); }
...
data[0] = counterInput.value;
ble.write(device_id, SERVICE, CHARACTERISTIC, data.buffer, success, failure);
## writeWithoutResponse
Writes data to a characteristic without confirmation from the peripheral.
ble.writeWithoutResponse(device_id, service_uuid, characteristic_uuid, data, success
, failure);
### Description
Function `writeWithoutResponse` writes data to a characteristic without a response from the peripheral. You are not notified if
the write fails in the BLE stack. The success callback is be called when the characteristic is written.
### Parameters
- __device_id__: UUID or MAC address of the peripheral
...
connect = function (device_id, success, failure) { var successWrapper = function(peripheral) { convertToNativeJS(peripheral); success(peripheral); }; cordova.exec(successWrapper, failure, 'BLE', 'connect', [device_id]); }
...
}, 5000);
*/
## connect
Connect to a peripheral.
ble.connect(device_id, connectSuccess, connectFailure);
### Description
Function `connect` connects to a BLE peripheral. The callback is long running. Success will be called when the connection is successful
. Service and characteristic info will be passed to the success callback in the [peripheral object](#peripheral-data). Failure is
called if the connection fails, or later if the peripheral disconnects. An peripheral object is passed to the failure callback.
[ble.scan](#scan) must be called before calling connect, so the plugin has a list of avaiable peripherals.
...
disconnect = function (device_id, success, failure) { cordova.exec(success, failure, 'BLE', 'disconnect', [device_id]); }
...
- __connectSuccess__: Success callback function that is invoked when the connection is successful.
- __connectFailure__: Error callback function, invoked when error occurs or the connection disconnects.
## disconnect
Disconnect.
ble.disconnect(device_id, [success], [failure]);
### Description
Function `disconnect` disconnects the selected device.
### Parameters
...
enable = function (success, failure) { cordova.exec(success, failure, "BLE", "enable", []); }
...
ble.showBluetoothSettings();
## enable
Enable Bluetooth on the device.
ble.enable(success, failure);
### Description
Function `enable` prompts the user to enable Bluetooth.
#### Android
...
isConnected = function (device_id, success, failure) { cordova.exec(success, failure, 'BLE', 'isConnected', [device_id]); }
...
- __success__: Success callback function that is invoked when the notification is removed. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
## isConnected
Reports the connection status.
ble.isConnected(device_id, success, failure);
### Description
Function `isConnected` calls the success callback when the peripheral is connected and the failure callback when *not* connected
.
### Parameters
...
isEnabled = function (success, failure) { cordova.exec(success, failure, 'BLE', 'isEnabled', []); }
...
}
);
## isEnabled
Reports if bluetooth is enabled.
ble.isEnabled(success, failure);
### Description
Function `isEnabled` calls the success callback when Bluetooth is enabled and the failure callback when Bluetooth is *not* enabled
.
### Parameters
...
list = function (success, failure) { cordova.exec(success, failure, 'BLE', 'list', []); }
n/a
notify = function (device_id, service_uuid, characteristic_uuid, success, failure) { console.log("WARNING: notify is deprecated, use startNotification"); cordova.exec(success, failure, 'BLE', 'startNotification', [device_id, service_uuid, characteristic_uuid]); }
n/a
read = function (device_id, service_uuid, characteristic_uuid, success, failure) { cordova.exec(success, failure, 'BLE', 'read', [device_id, service_uuid, characteristic_uuid]); }
...
- __success__: Success callback function that is invoked when the connection is successful. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
## read
Reads the value of a characteristic.
ble.read(device_id, service_uuid, characteristic_uuid, success, failure);
### Description
Function `read` reads the value of the characteristic.
Raw data is passed from native code to the callback as an [ArrayBuffer](#typed-arrays).
...
readRSSI = function (device_id, success, failure) { cordova.exec(success, failure, 'BLE', 'readRSSI', [device_id]); }
...
}
);
## readRSSI
Read the RSSI value on the device connection.
ble.readRSSI(device_id, success, failure);
### Description
Samples the RSSI value (a measure of signal strength) on the connection to a bluetooth device. Requires that you have established
a connection before invoking (otherwise an error will be raised).
### Parameters
...
scan = function (services, seconds, success, failure) { var successWrapper = function(peripheral) { convertToNativeJS(peripheral); success(peripheral); }; cordova.exec(successWrapper, failure, 'BLE', 'scan', [services, seconds]); }
...
- [ble.enable](#enable)
- [ble.readRSSI](#readrssi)
## scan
Scan and discover BLE peripherals.
ble.scan(services, seconds, success, failure);
### Description
Function `scan` scans for BLE devices. The success callback is called each time a peripheral is discovered. Scanning automatically
stops after the specified number of seconds.
{
"name": "TI SensorTag",
...
showBluetoothSettings = function (success, failure) { cordova.exec(success, failure, "BLE", "showBluetoothSettings", []); }
...
Function `stopStateNotifications` calls the success callback when Bluetooth state notifications have been stopped.
## showBluetoothSettings
Show the Bluetooth settings on the device.
ble.showBluetoothSettings(success, failure);
### Description
Function `showBluetoothSettings` opens the Bluetooth settings for the operating systems.
#### iOS
...
startNotification = function (device_id, service_uuid, characteristic_uuid, success, failure) { cordova.exec(success, failure, 'BLE', 'startNotification', [device_id, service_uuid, characteristic_uuid]); }
...
- __success__: Success callback function that is invoked when the connection is successful. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
## startNotification
Register to be notified when the value of a characteristic changes.
ble.startNotification(device_id, service_uuid, characteristic_uuid, success, failure
);
### Description
Function `startNotification` registers a callback that is called *every time* the value of a characteristic changes. This method
handles both `notifications` and `indications`. The success callback is called multiple times.
Raw data is passed from native code to the success callback as an [ArrayBuffer](#typed-arrays).
...
startScan = function (services, success, failure) { var successWrapper = function(peripheral) { convertToNativeJS(peripheral); success(peripheral); }; cordova.exec(successWrapper, failure, 'BLE', 'startScan', [services]); }
...
console.log(JSON.stringify(device));
}, failure);
## startScan
Scan and discover BLE peripherals.
ble.startScan(services, success, failure);
### Description
Function `startScan` scans for BLE devices. The success callback is called each time a peripheral is discovered. Scanning will
continue until `stopScan` is called.
{
"name": "TI SensorTag",
...
startScanWithOptions = function (services, options, success, failure) { var successWrapper = function(peripheral) { convertToNativeJS(peripheral); success(peripheral); }; options = options || {}; cordova.exec(successWrapper, failure, 'BLE', 'startScanWithOptions', [services, options]); }
...
function() { console.log("stopScan failed"); }
);
## startScanWithOptions
Scan and discover BLE peripherals, specifying scan options.
ble.startScanWithOptions(services, options, success, failure);
### Description
Function `startScanWithOptions` scans for BLE devices. It operates similarly to the `startScan` function, but allows you to specify
extra options (like allowing duplicate device reports). The success callback is called each time a peripheral is discovered. Scanning
will continue until `stopScan` is called.
{
"name": "TI SensorTag",
...
startStateNotifications = function (success, failure) { cordova.exec(success, failure, "BLE", "startStateNotifications", []); }
...
}
);
## startStateNotifications
Registers to be notified when Bluetooth state changes on the device.
ble.startStateNotifications(success, failure);
### Description
Function `startStateNotifications` calls the success callback when the Bluetooth is enabled or disabled on the device.
__States__
...
stopNotification = function (device_id, service_uuid, characteristic_uuid, success, failure) { cordova.exec(success, failure, 'BLE', 'stopNotification', [device_id, service_uuid, characteristic_uuid]); }
...
ble.startNotification(device_id, "FFE0", "FFE1", onData, failure);
## stopNotification
Stop being notified when the value of a characteristic changes.
ble.stopNotification(device_id, service_uuid, characteristic_uuid, success, failure
);
### Description
Function `stopNotification` stops a previously registered notification callback.
### Parameters
...
stopScan = function (success, failure) { cordova.exec(success, failure, 'BLE', 'stopScan', []); }
...
);
## stopScan
Stop scanning for BLE peripherals.
ble.stopScan(success, failure);
### Description
Function `stopScan` stops scanning for BLE devices.
### Parameters
...
stopStateNotifications = function (success, failure) { cordova.exec(success, failure, "BLE", "stopStateNotifications", []); }
...
}
);
## stopStateNotifications
Stops state notifications.
ble.stopStateNotifications(success, failure);
### Description
Function `stopStateNotifications` calls the success callback when Bluetooth state notifications have been stopped.
## showBluetoothSettings
...
write = function (device_id, service_uuid, characteristic_uuid, value, success, failure) { cordova.exec(success, failure, 'BLE', 'write', [device_id, service_uuid, characteristic_uuid, value]); }
...
- __success__: Success callback function that is invoked when the connection is successful. [optional]
- __failure__: Error callback function, invoked when error occurs. [optional]
## write
Writes data to a characteristic.
ble.write(device_id, service_uuid, characteristic_uuid, data, success, failure);
### Description
Function `write` writes data to a characteristic.
### Parameters
- __device_id__: UUID or MAC address of the peripheral
...
writeCommand = function (device_id, service_uuid, characteristic_uuid, value, success, failure) { console.log("WARNING: writeCommand is deprecated, use writeWithoutResponse"); cordova.exec(success, failure, 'BLE', 'writeWithoutResponse', [device_id, service_uuid, characteristic_uuid, value]); }
n/a
writeWithoutResponse = function (device_id, service_uuid, characteristic_uuid, value, success, failure) { cordova.exec(success, failure, 'BLE', 'writeWithoutResponse', [device_id, service_uuid, characteristic_uuid, value]); }
...
data[0] = counterInput.value;
ble.write(device_id, SERVICE, CHARACTERISTIC, data.buffer, success, failure);
## writeWithoutResponse
Writes data to a characteristic without confirmation from the peripheral.
ble.writeWithoutResponse(device_id, service_uuid, characteristic_uuid, data, success
, failure);
### Description
Function `writeWithoutResponse` writes data to a characteristic without a response from the peripheral. You are not notified if
the write fails in the BLE stack. The success callback is be called when the characteristic is written.
### Parameters
- __device_id__: UUID or MAC address of the peripheral
...