-
-
Notifications
You must be signed in to change notification settings - Fork 3
Open
Description
I cannot connect more than a peripheral on Android at the same time (not tested on iOS).
Steps to reproduce:
- start scan
- the first peripheral is discovered then call stopScan and connectPeripheral
- the first peripheral is connected and the event didConnectPeripheral fired
- start a new scan
- the second peripheral is discovered then call stopScan and connectPeripheral
- the second peripheral is not connected and no events fired
var BLE = require("appcelerator.ble");
var centralManager = BLE.initCentralManager();
centralManager.addEventListener('didDiscoverPeripheral', function (e) {
Ti.API.info('> [didDiscoverPeripheral] name: ' + e.peripheral.name + ', address: ' + e.peripheral.address + ', connected: ' + e.peripheral.isConnected);
if (!e.peripheral.isConnected) {
stopScan();
centralManager.connectPeripheral({peripheral: e.peripheral});
}
});
centralManager.addEventListener('didConnectPeripheral', function(e) {
Ti.API.info('> [didConnectPeripheral] name: ' + e.peripheral.name + ', address: ' + e.peripheral.address);
});
centralManager.addEventListener('didDisconnectPeripheral', function(e) {
Ti.API.info('> [didDisconnectPeripheral] name: ' + e.peripheral.name + ', address: ' + e.peripheral.address);
});
centralManager.addEventListener('didFailToConnectPeripheral', function(e) {
Ti.API.info('> [didFailToConnectPeripheral] name: ' + e.peripheral.name + ', address: ' + e.peripheral.address + ', error: (' + errorCode + ') ' + errorDescription);
});
function startScan() {
if (centralManager.isScanning) {
alert('Already scanning, please stop scan first!');
return;
} else if (centralManager.state != BLE.MANAGER_STATE_POWERED_ON) {
alert('Please enable Bluetooth.');
return;
}
console.log('=== startScan ===');
setTimeout(function() {
stopScan();
}, 10000);
const ITAG_SERVICE = '0000ffe0-0000-1000-8000-00805f9b34fb';
centralManager.startScan({services: [ITAG_SERVICE]});
}
function stopScan() {
if (centralManager.isScanning) {
console.log('=== stopScan ===');
centralManager.stopScan();
}
}
function test() {
startScan();
}
Metadata
Metadata
Assignees
Labels
No labels