Reputation: 150684
Basically my question is very similar to BLE peripheral: scanning while connected, only that I refer to the master and not to the peripherals.
If a master is already connected to one or more peripherals, is it still able to scan for other peripherals that do advertising?
I'm also using bleno
for the peripherals and noble
for the master, but I think that the answer to this question does not depend on the actual modules, but on the Bluetooth Low Energy specification, does it?
Upvotes: 2
Views: 2405
Reputation: 17460
Yes, a central can scan while connections to other peripherals are established. Please note that an individual peripheral may stop advertising when it is connected to a central. This may add confusion when testing.
Here is a minimal demonstration using noble:
var noble = require('noble');
var connectedIDs = {};
noble.on('stateChange', (state) => {
if (state == 'poweredOn') {
noble.startScanning([], true);
}
});
noble.on('discover', (peripheral) => {
if (connectedIDs[peripheral.id] == 'known') {
console.log(new Date() + ' ' + peripheral.id + ' discovered again');
} else {
console.log(new Date() + ' ' + peripheral.id + ' discovered first time')
connectedIDs[peripheral.id] = 'known';
// periodically connect to the same peripheral so we get the error
// message telling us that we are already connected
setInterval( () => {
peripheral.connect( (err) => {
if (err) {
console.log(new Date() + ' ' + peripheral.id + ' ' + err);
return;
}
console.log(new Date() + ' ' + peripheral.id + ' connected');
});
}, 1000);
}
});
This code example connects to all peripherals it discovers and simultaneously logs the id of peripherals it receives advertisement data from.
Output (truncated some columns and lines):
10:51:06 8652... Error: Peripheral already connected
10:51:06 567b... Error: Peripheral already connected
10:51:06 f0ba... Error: Peripheral already connected
10:51:06 d095... Error: Peripheral already connected
10:51:06 3800... Error: Peripheral already connected
10:51:07 6c20... discovered first time
10:51:07 f0ba... Error: Peripheral already connected
10:51:07 d095... Error: Peripheral already connected
10:51:07 3800... Error: Peripheral already connected
10:51:07 6c20... discovered again
10:51:08 8652... Error: Peripheral already connected
10:51:08 567b... Error: Peripheral already connected
10:51:08 f0ba... Error: Peripheral already connected
10:51:08 6c20... discovered again
10:51:08 d095... Error: Peripheral already connected
10:51:08 8652... Error: Peripheral already connected
10:51:08 3800... Error: Peripheral already connected
10:51:08 6c20... discovered again
10:51:08 f0ba... Error: Peripheral already connected
10:51:08 d095... Error: Peripheral already connected
10:51:08 3800... Error: Peripheral already connected
10:51:08 6c20... connected
10:51:08 6c20... connected
What happened?
Multiple peripherals have already been connected to noble when 6c20...
is discovered the first time. The error messages of the repeating connection attempts show that the peripherals are still connected while scanning. In my example run, I had 6 BLE peripherals connected and 6c20...
was the 7th to join the party. I used noble v1.3.0 and node v4.2.4 on a MacBookPro mid-2015 with OS X 10.11.3.
This doesn't answer the second question: Does this behavior depend on the actual modules or on the Bluetooth Low Energy specification?
AFAIK, the BLE specification doesn't specify an amount of connections a central has to support. AFAIK because the BLE Core Spec is rather big and all references to simultaneously and multiple connections I could find state that it depends on the implementation. So, this seems to totally depend on the BLE product which consists of hardware and software. Even if the BLE spec would specify it, I would prefer to check the datasheet of the product. In addition, it depends on the software running on the host, too. Luckily, noble does.
To give an example, let's have a look at the datasheet of Nordic's Soft Device S120: https://www.nordicsemi.com/eng/nordic/download_resource/26275/14/32008006
The S120 soft device is a BLE stack (firmware) for Nordic's NRF51 series of BLE ICs (most known example is the nRF51822).
Here is quote from the datasheet linked above:
The SoftDevice supports eight concurrent master connections and an additional Scanner/Initiator role. When the maximum number of simultaneous connections are established, the Scanner role will be supported for new device discovery though the initiator is not available at that time.
Upvotes: 2