Code Monkey home page Code Monkey logo

Comments (4)

h2zero avatar h2zero commented on May 28, 2024

Some logs would help but I suspect that the delay is a bit too short, do you know what the connection interval is?

from nimble-arduino.

jhmaloney avatar jhmaloney commented on May 28, 2024

The connection interval (desc->conn_itvl) is 24 units, which I believe is 30 msecs. Does that mean I should make my delay between notify's a bit over 30 msecs to avoid using up all the buffer? Is there a way to force a more frequent connection interval?

from nimble-arduino.

jhmaloney avatar jhmaloney commented on May 28, 2024

I added a print to the onStatus callback. It looks like the first 8 notify's are okay but it starts to fail after that:

onStatus TX status: 1 rc: 0
onStatus TX status: 1 rc: 0
onStatus TX status: 1 rc: 0
onStatus TX status: 1 rc: 0
onStatus TX status: 1 rc: 0
onStatus TX status: 1 rc: 0
onStatus TX status: 1 rc: 0
onStatus TX status: 1 rc: 0
onStatus TX status: 4 rc: 6
onStatus TX status: 4 rc: 6
onStatus TX status: 4 rc: 6
onStatus TX status: 4 rc: 6
...

I increased the delay to a full second (1000 msecs) and it still sends only the first eight.

from nimble-arduino.

jhmaloney avatar jhmaloney commented on May 28, 2024

I found my problem.

I was calling writeTest() in response to a request coming from the client. Thus, it was called from the onWrite() callback in my subclass of BLECharacteristicCallbacks. I'm guessing that the BLE stack holds a lock until the onWrite() callback returned. Thus, NimBLE was queuing notify messages to be sent when onWrite() returned, but when writeTest() did too many notify() calls it ran out of buffers.

The fix was to have onWrite() set a flag to request that writeTest() be called from the loop() function. With that change, writeTest() can send thousands of bytes. I'm seeing throughputs of about 5k bytes/second from a micro:bit V2 to my MacBook Pro, which is great!

I now have a new problem.

I'm using a delay in the writeTest() loop to avoid queuing data faster than NimBLE can send it. To maximize bandwidth, I want to minimize that delay. Through trial-and-error, I've found that 12 msecs works but 10 msecs results in errors (status: 4, return code: 6) and lost data. I'd rather not depend on a delay for this.

Is there a function I can call to be sure that a buffer is available for doing a setValue and notify on an attribute? Alternatively, is there some way to get an immediate return code indicating that the setValue or notify failed and should be tried again later? (I'm using onStatus now, but I'm not sure exactly when that gets called. Is it triggered by the setValue() or the notify() call? Is onStatus() called immediately when the error occurs?

Thanks!

from nimble-arduino.

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.