Git Product home page Git Product logo

Comments (12)

PimButton avatar PimButton commented on August 14, 2024

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.

sandeepmistry avatar sandeepmistry commented on August 14, 2024

@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.

PimButton avatar PimButton commented on August 14, 2024

@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.

Asoustek avatar Asoustek commented on August 14, 2024

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.

PimButton avatar PimButton commented on August 14, 2024

@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.

sandeepmistry avatar sandeepmistry commented on August 14, 2024

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.

Asoustek avatar Asoustek commented on August 14, 2024

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.

PimButton avatar PimButton commented on August 14, 2024

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.

Asoustek avatar Asoustek commented on August 14, 2024

@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.

sandeepmistry avatar sandeepmistry commented on August 14, 2024

I would suggest trying to add a process.nextTick(function() { ... } or setTimeout in the onWriteFinished function.

from node-bluetooth-hci-socket.

sandeepmistry avatar sandeepmistry commented on August 14, 2024

@PimButton @Asoustek ping ... any progress on this?

from node-bluetooth-hci-socket.

sandeepmistry avatar sandeepmistry commented on August 14, 2024

Closing this due to lack of activity and progress for now.

from node-bluetooth-hci-socket.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.