Detecting bluetooth device disconnects/crashes
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 30/100
- Issue type
- Bug
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- javascript, node.js
- Domain
- embedded-iot, networking
Research direction
Start with lib/connection.js and inspect the read callback, including how zero-length buffers and read errors are emitted. Reproduce the Bluetooth shutdown behavior described in the issue and determine the expected disconnect event and timing. Done means the disconnect behavior is defined and covered without assuming zero-length buffers are impossible during a valid connection.
Written by the indexing model from the issue text.
Description
Hi!
I couldn't find a way to detect if a connection has crashed or disconnected so I tried to implement my own.
In lib/connection.js, I noticed that - if I printed the chunks of the read method - they stop printing as soon as I turn off my bluetooth device; after ~20seconds of apparent frozen behavior, this method continued working, printing chunks of zero length buffers.
Thus, I added the following line
if(chunk.length == 0){ self.emit('error')}
in
(function read(){
self.isOpen() && self.port.read((err, chunk) => {
process.nextTick(read);
if(err) return self.emit('error', err);
self.emit('data', chunk);
if(chunk.length == 0){ self.emit('error')}
});
})();
This allows me to fetch error events like so:
connect(address, 1, (err, linkage) => {
if (err) {
console.log('connection attempt error');
} else {
linkage.on('error', (err) => {
console.log('disconnected!);
});
}
)}
However my approach assumes I won't be receiving zero length buffers when connected which I realize that might not always be true (or not for all devices);
Also, any thoughts on how to detect the disconnect before the ~20seconds pass?
Thanks!
- Dominant language
- C++
- Stars
- 205
- Forks
- 56
- PR merge metrics
- No merged PRs in 30d
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from lsongdev/node-bluetooth
-
bug
Difficulty 4/5 3-5 days Newbie friendliness 45/100
lsongdev/node-bluetooth#61 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 25/100
lsongdev/node-bluetooth#60 ·
-
Maintenance status? Open
Difficulty 1/5 Under an hour Newbie friendliness 10/100
lsongdev/node-bluetooth#55 · 8 comments ·
-
Battery status? Open
Difficulty 5/5 Over a week Newbie friendliness 20/100
lsongdev/node-bluetooth#54 · 1 comment ·
-
BT node Open
Difficulty 5/5 Over a week Newbie friendliness 10/100
lsongdev/node-bluetooth#53 ·
All issues in lsongdev/node-bluetooth
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
flutter-webrtc/flutter-webrtc#2206 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
google-ai-edge/LiteRT-LM#3739 ·
-
Component: GLib
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
brave/brave-browser#59300 ·
-
Mute ydb/tests/functional/dstool/test_canonical_requests.py.Test.test_group_take_snapshot in main Openai_reviewed
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
ydb-platform/ydb#53974 · 3 comments ·