• Hi I'm benchmarking sensors and bluetooth throughputs on the BangleJS 2 right now, also working on a free multithreaded driver system that will unlock native android and IOS support on top of browsers in js, with the help of the Capacitor build library for mobile apps.

    Anyway I'm wondering why Bluetooth.write on the Bangle 2 device schedules in 128 byte chunks? Or at least that's what I am receiving on my end. I'm trying to simply pack 250 byte buffers which is more typical for eking out nRF52 performance. I tested my own nRF52 hardware in the same web streaming context and it was fine pumping the maximum packet size limit at 1M or 2M PHY into my browser system as browser and native mobile can do up to 512 MTU at either bluetooth 4 or 5 speeds (of course only 20 MTU on android web BLE but it's trash). Is there a simple function like setMTU in the espruino code that can change the packet size limiting on the Bluetooth.write call? I've had to dig pretty deep into the sources already for a number of other things but am not finding this one.

    I'll release a dummy app afterward to demonstrate the stack I have as it's pretty nice and minimal for cross platform dev. I'm doing a bunch of medical sensing related work so the Bangle 2 is a convenient placeholder/benchmark for a bunch of projects, keep up the good work.

  • It is a compromise between RAM requirements of bluetooth stack and compatibility and speed, 128 (=MTU131) should be plenty for anything. speed can be affected by other parameters too like connection interval, it is not so clearcut that more is better in this case. you can change it in board file but it also needs tuning of APP RAM BASE
    https://github.com/espruino/Espruino/blob/master/boards/BANGLEJS2.py#L51
    when you set the base too low firmware will not start. you should also decrease variables for same amount of bytes (1 JS variable is 13 bytes). as Bangle supports multiple connections, increasing MTU by 128 needs many times more of RAM to support that.

  • Thanks, understood, I will adapt to make the most of the 128. I found that note in that code about IOS compatibility issues on the packet size as well so noted.

  • Actually one other thing, where is the code for how the BLE connection is negotiated? I've been having a hell of a time getting nRF53 to play nice making successful connections while nRF52 "just worked" for me with the examples that came with it. There's some issue with connection intervals that I cannot solve even with the same settings between dev kits so I've been trying to find more reference material.

  • Most code for Bluetooth setup is in https://github.com/espruino/Espruino/blob/master/targets/nrf5x/bluetooth.c

    I'd argue that Espruino/the Bangle firmware is pretty well tested at the moment - if you'd having a problem connecting with nRF53 then it's probably an issue with the firmware there.

    At a first guess, it might be that the Bangle is negotiating to use a higher MTU and then there's an issue with your buffer allocation on the nRF53? Things like that can cause issues like that when you can connect to some kinds of devices but not others

  • from the post I was guessing the nrf53 issue was not Espruino related at all and it was just a random nrf53 question

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Bangle JS 2 Bluetooth.write() only emitting 128 byte packets? How to set to 250 (max for nRF52)?

Posted by Avatar for user158442 @user158442

Actions