Open mdgagne opened 7 years ago
This is related to https://github.com/sandeepmistry/noble/issues/480
@sandeepmistry Thanks for you reply. I read through the post and tested the modification that you made to the connection parameters; however, I'm still running into this problem. I've also attempted adding reconnect logic. Once this occurs (about 50-75% of the time) I have to restart the node app.
Could you explain the problem to me? Is there any additional information I could provide to help with a fix?
The kernel is sending out a disconnect message based on some timing conditions
2017-03-22 21:32:53.982540 < HCI Command: Disconnect (0x01|0x0006) plen 3
handle 0 reason 0x13
Reason: Remote User Terminated Connection
@sandeepmistry Thanks for pointing out the specific issues from the hci dump for me. I can reproduce this intermittently with gatttool so it may be an error with the devices. In this scenario when my node app reconnects hcidump shows a successful reconnect; however, I don't receive any of the events that I expect from the noble device. How should I be attempting reconnect?
@mdgagne
I can reproduce this intermittently with gatttool so it may be an error with the devices.
Maybe we should close then?
How should I be attempting reconnect?
What does your current code look like?
@sandeepmistry Even if there is an issue with the device, I dont think that disconnect (at any time) should prevent noble from being able to reconnect. Here is an modified example node-metawear example that reproduces the problem. I added some simple reconnect logic that attempts to reconnect anytime a connection is lost. This example assumes only 1 metawear device is in range.
var devices = require('node-metawear');
var rate = parseFloat(process.argv[2]) || 50;
var range = parseFloat(process.argv[3]) || 2;
var connected =false;
function makeConnection () {
if (connected) {
console.log ("already connected");
}
console.log ("not connected, connecting");
devices.discover(function(device) {
console.log('discovered device ', device.address);
device.on('disconnect', function() {
console.log('we got disconnected! :( ');
connected = false;
});
device.connectAndSetup(function(error) {
connected = true;
console.log('were connected!');
console.log('Start accelerometer with ' + rate + 'hz ang +-' + range + 'g');
var accelerometer = new device.Accelerometer(device);
var logger = new device.Log(device);
accelerometer.setOutputDataRate(rate);
accelerometer.setAxisSamplingRange(range);
logger.startLogging(false);
accelerometer.setConfig();
accelerometer.enableNotifications();
accelerometer.enableAxisSampling();
accelerometer.start();
accelerometer.onChange(function(data) {
console.log("x:", data.x, "\t\ty:", data.y, "\t\tz:", data.z);
});
});
});
}
makeConnection ();
setInterval (makeConnection, 10000);
Greetings,
I'm using the node-metawear library to collect accelerometer data over BLE and have been running into a consistent disconnect problem using a raspberry pi 3 running the latest raspbian jessie image with updates and the latest build of bluez (5.44) I downloaded and compiled. I've dug around here, on the node-metawear git, and noble git. Posting here seems the most relevant spot because it seems to be a NobleDevice related problem.
Anyhow, I'm running into disconnect problems fairly regularly. Basically, the 'disconnect' event fires sometime between discovery and connectAndSetup completion. My disconnect event callback simply schedule a new discovery/connect 1000ms later using setTimeout; however, when this problem occurs the app never successfully connects to the sensor. I've included an hcidump log capturing the intial discovery and connected attempt followed by roughly 10 seconds of thrashing before the app closes. Please let me know if I can include any additional information.