Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot connect more than one peripheral #313

Open
alexlarocca opened this issue Nov 2, 2022 · 1 comment
Open

Cannot connect more than one peripheral #313

alexlarocca opened this issue Nov 2, 2022 · 1 comment

Comments

@alexlarocca
Copy link
Sponsor

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();
}
@alexlarocca
Copy link
Sponsor Author

The issue reported above occurs only on Android. Test on iOS was successfull.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant