Comments (12)
Hi @sandeepmistry, I know you are very busy so I don't want to pressure you in any way. I you can tell me if setting DEBUG causes some sort of extra reset or does something else that I can trigger manually it would be of great help so I can continue testing.
Thanks for the amazing work, again!
from node-bluetooth-hci-socket.
@PimButton debug will have impact on the timing.
Could you please try the latest, node-bluetooth-hci-socket version. I'm wondering if the following change has any impact: https://github.com/sandeepmistry/node-bluetooth-hci-socket/pull/31/files
from node-bluetooth-hci-socket.
@sandeepmistry thanks for your reply!
Unfortunately even with version 0.5.0 the same behaviors occurs. It seems about 50/50 whether the state
is poweredOff or poweredOn. I also tried calling noble.stopScanning()
before called the onStateChange function but that has no effect as well...
from node-bluetooth-hci-socket.
I am also seeing this issue, same scenario after multiple runs sometimes i never get the state changed event, but in DEBUG=* mode i do.. I'm running on Windows 10 with the latest version of noble..
After some digging i've noticed that adding this bit of code to the BluetoothHciSocket.write function gives me (seemingly) 100% consistency... Now admittedly i don't know anything about how this code works so maybe this just resolves the timing issue on my machine only.
var lastWrite = 0;
BluetoothHciSocket.prototype.write = function(data) {
var waitTime = 0;
var thisWrite = new Date().getTime();
if (lastWrite != 0)
{
if (thisWrite - lastWrite < 5)
{
waitTime = 5;
}
}
lastWrite = thisWrite;
var waitTimer = thisWrite;
while(new Date().getTime() - waitTimer < waitTime){}
if (this._mode === 'raw' || this._mode === 'user') {
var type = data.readUInt8(0);
if (HCI_COMMAND_PKT === type) {
this._usbDevice.controlTransfer(usb.LIBUSB_REQUEST_TYPE_CLASS | usb.LIBUSB_RECIPIENT_INTERFACE, 0, 0, 0, data.slice(1));
} else if(HCI_ACLDATA_PKT === type) {
this._aclDataOutEndpoint.transfer(data.slice(1));
}
}
};
from node-bluetooth-hci-socket.
@Asoustek, sounds promising, thanks for your reply! I am not able to test this week but once I'm back at work I will give it a try.
Curious if this might give @sandeepmistry a clue about what's going on.
from node-bluetooth-hci-socket.
Looking at the node-usb API docs both this._usbDevice.controlTransfer
and this._aclDataOutEndpoint.transfer
accept callback parameters.
@PimButton @Asoustek it would be great if you could look into queuing both ACL and command transfer data. Basically, if the callback has not being called for each, do not transfer the data until it is.
from node-bluetooth-hci-socket.
Submitted #33
Unfortunately unable to test it, maybe once i get back to my bluetooth machine. You could add consoleLog in the onWriteFinished inside the if to make sure we're clearing the buffer.
If @PimButton or @sandeepmistry have time to pull the PR and try it i'd appreciate, otherwise i'll test my own a bit later.
from node-bluetooth-hci-socket.
I'm back at the office and was able to test :)
@Asoustek thanks for the quick PR! I pulled it, but unfortunately it did not work for me, the same behavior still occurred. However, the piece of code that you wrote above does work for me! As far as I can see you implemented the changes suggested by @sandeepmistry correctly so maybe something else is going on? Sandeep, do you understand why the manual time delay does work, but the callback does not?
from node-bluetooth-hci-socket.
@PimButton yeah unfortunately i was seeing similar things, obeying the callbacks still occasionally gives me a weird state, but the actual timeout does seem to work very consistently for me.. Not sure if my PR is wrong, but i think it looks ok.
Maybe @sandeepmistry knows.
from node-bluetooth-hci-socket.
I would suggest trying to add a process.nextTick(function() { ... }
or setTimeout
in the onWriteFinished
function.
from node-bluetooth-hci-socket.
@PimButton @Asoustek ping ... any progress on this?
from node-bluetooth-hci-socket.
Closing this due to lack of activity and progress for now.
from node-bluetooth-hci-socket.
Related Issues (20)
- Segfaults/assertion errors (when no BT hardware is available?) HOT 1
- Failed Install - Win 10 HOT 1
- Error: No compatible USB Bluetooth 4.0 device found! HOT 1
- Dell precision m4800 Error: No compatible USB Bluetooth 4.0 device found!
- TypeError: Cannot read property 'endpoint' of undefined HOT 1
- . HOT 1
- Maintenance status ? HOT 6
- Add new device HOT 2
- Adapter unavailable in windows bluetooth settings
- Issues with bluetooth adapter 4.2 and 5.0
- raspberry pi3 HOT 3
- Installation fails in Docker-iobroker container on Raspi4 running Raspbian Buster HOT 1
- Add new device intel wireless bluetooth USB\VID_8087&PID_0AAA HOT 1
- Unable to install on Linux Mint HOT 1
- Adapter not found HOT 1
- Error : LIBUSB_ERROR_ACCES HOT 1
- Canβt install HOT 1
- Socket.write not writing commands HOT 1
- Installation fails (Arch Linux, node-gyp 9.3.0) HOT 3
- I need a C++ for windows sample
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-bluetooth-hci-socket.