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
Simultaneous connection with ANCS and other peripherals #3
Comments
My code right now: var BleAncs = require('../index');
var Able = require('../lib/able');
var ancs = new BleAncs();
ancs.on('notification', function(notification) {
notification.readTitle(function(title) {
notification.readMessage(function(message) {
console.log('Notification: ' + notification); }); }); });
var SERVICE = '6e400001b5a3f393e0a9e50e24dcca9e';
var TX = '6e400002b5a3f393e0a9e50e24dcca9e';
var RX = '6e400003b5a3f393e0a9e50e24dcca9e';
var state = {peripheral: null, tx: null};
function onRead(v) {
console.log('Read:', v.toString());};
var other = new Able()
.on('stateChange', function(state) {
if (state == 'poweredOn') { other.startScanning(); }
else { other.stopScanning(); }})
.on('discover', function(p) {
console.log('peripheral', p.uuid);
if (p.advertisement.serviceUuids.indexOf(SERVICE) != -1) {
other.stopScanning();
p.connect(function(err) {
p.findService(SERVICE, function(err, services) {
services[0].discoverCharacteristics([], function(err, cs) {
cs.forEach(function(c) {
if (c.uuid == TX) {
state.tx = c; }
else if (c.uuid == RX) {
c.notify(true);
c.on('read', onRead); }}); }); }); });
state.peripheral = p; }}); When I comment out either the ANCS or UART part, the other part works as expected. When I try the full script, only ANCS works:
The device that should connect and doesn’t succeed is |
Hmm... This should be possible. Able is really just Noble and Bleno combined. I would check out the index.js for ble-ancs. I bet it is doing something in there that is messing things up. You should be able to move most of this code into that file. |
I’m trying a custom
How would you recommend proceeding? It seems like advertising conflicts with scanning, and like established connections die after a while.
|
One thing I would check is if the Bluetooth device you are using supports Advertising and Scanning at the same time. Try doing I am not sure what the difference is to be honest. I think it could be a good idea to try using |
The # hciconfig hci0 lestates Supported link layer states: YES Non-connectable Advertising State YES Scannable Advertising State YES Connectable Advertising State YES Directed Advertising State YES Passive Scanning State YES Active Scanning State YES Initiating State/Connection State in Master Role YES Connection State in the Slave Role YES Non-connectable Advertising State and Passive Scanning State combination YES Scannable Advertising State and Passive Scanning State combination YES Connectable Advertising State and Passive Scanning State combination YES Directed Advertising State and Passive Scanning State combination YES Non-connectable Advertising State and Active Scanning State combination YES Scannable Advertising State and Active Scanning State combination YES Connectable Advertising State and Active Scanning State combination YES Directed Advertising State and Active Scanning State combination YES Non-connectable Advertising State and Initiating State combination YES Scannable Advertising State and Initiating State combination YES Non-connectable Advertising State and Master Role combination YES Scannable Advertising State and Master Role combination YES Non-connectable Advertising State and Slave Role combination YES Scannable Advertising State and Slave Role combination YES Passive Scanning State and Initiating State combination YES Active Scanning State and Initiating State combination YES Passive Scanning State and Master Role combination YES Active Scanning State and Master Role combination YES Passive Scanning State and Slave Role combination YES Active Scanning State and Slave Role combination YES Initiating State and Master Role combination/Master Role and Master Role combination Good idea to compare the |
I can’t reproduce the disconnection issue anymore so I assume that was an issue with my UART device. Still, I can’t have both the UART device and iOS/ANCS connected at the same time. This is my simplified test script now: var Able = require('./lib/able');
var BleAncs = require('./index');
var TRY_WITH_ANCS = false;
var UART = '6e400001b5a3f393e0a9e50e24dcca9e';
function TestIssue3() {
this._able = new Able()
.on('stateChange', this.onStateChange.bind(this))
.on('discover', this.onDiscover.bind(this));
if (TRY_WITH_ANCS) this._able.on('advertisingStart', BleAncs.prototype.onAdvertisingStart.bind(this));
};
TestIssue3.prototype.onStateChange = function(state) {
console.log('state', state);
if (TRY_WITH_ANCS) BleAncs.prototype.onStateChange.call(this, 'poweredOn');
if (state == 'poweredOn') this._able.startScanning();
else this._able.stopScanning();
};
TestIssue3.prototype.onDiscover = function(peripheral) {
console.log('discovered', peripheral.uuid);
if (this._uart || peripheral.advertisement.serviceUuids.indexOf(UART) == -1) return;
console.log('found uart device');
this._able.stopScanning();
this._uart = peripheral;
peripheral.connect(function(e) { console.log('connected', e); });
};
var test = new TestIssue3(); When
The full log with When
The full log with So it seems that we can’t connect to a peripheral while advertising as a peripheral. I’ll try connecting to the UART peripheral once the role-switching for ANCS has finished. Better ideas welcome :-) |
Trying to connect to the UART peripheral after var Able = require('./lib/able');
var BleAncs = require('./index');
var util = require('util');
var events = require('events');
var UART = '6e400001b5a3f393e0a9e50e24dcca9e';
function TestIssue3b() {
this._able = new Able()
.on('encryptChange', this.startUart.bind(this))
.on('discover', this.onDiscover.bind(this))
.on('stateChange', this.onStateChange.bind(this))
.on('accept', this.onAccept.bind(this))
.on('mtuChange', this.onMtuChange.bind(this))
.on('advertisingStart', this.onAdvertisingStart.bind(this))
.on('encryptChange', this.onEncryptChange.bind(this))
.on('encryptFail', this.onEncryptFail.bind(this))
.on('connect', this.onConnect.bind(this))
this._characteristics = {};
this._notifications = {};
this._lastUid = null;
};
util.inherits(TestIssue3b, BleAncs);
TestIssue3b.prototype.startUart = function() {
console.log('scanning for uart');
this._able.startScanning();
};
TestIssue3b.prototype.onDiscover = function(peripheral) {
console.log('discovered', peripheral.uuid);
if (this._uart || peripheral.advertisement.serviceUuids.indexOf(UART) == -1) return;
console.log('found uart device');
this._able.stopScanning();
this._uart = peripheral;
peripheral.connect(function(e) { console.log('connected', e); });
};
var test = new TestIssue3b(); The error (same as above):
I’m out of ideas. Do you think this is a bug in |
Hmm… my guess is that the Edison Chipset or Bluez may not like acting as a Central and Peripheral at the same time. Is the BLE built in? You could probably add a second dongle, but then you might as well just have 2 separate programs running. There error below is coming from Bluez or the HW. It might be worth tracking down in the Bluez source to figure out what triggers the Command Disallowed error.
It is really weird that it works separately, but not when combined!
|
Yes, there’s a Broadcom BCM43340 chip integrated in the Edison. Is there a way to instruct the second Bluetooth program (Node script) to use the second dongle, and not try the same one as the first Bluetooth program? |
Noble, Bleno, and Able all have language to specify which dongle to use. Checkout |
Works well when I run one with Closing this bug since it seems a driver/hardware issue, not something in ble-ancs or able. |
I’m trying to use ble-ancs to connect to my iPhone for ANCS, to my heart rate sensor, and to an UART device (Bluefruit Micro) from one Node script. Both the sensor and the UART device are BLE peripherals. Before I spend hours trying to make it work, should this be possible in ble-ancs / able already?
[edit: removed irrelevant example, will update if I have a clearer example]
The text was updated successfully, but these errors were encountered: