"Streaming" data from MDBT42 via bluetooth

Posted on
  • I want to stream ADC data from the MDBT42 module via web bluetooth. The sampling & DMA part works nicely (thanks for the low-level library Gordon!). With 256x oversampling, I have a theoretical 781 effective sample / second. Each sample is an Uint16 value.
    I have seen the Web bluetooth and Web Bluetooth Dashboard tutorials, and looks like that can work.
    Need to fiddle with serialization, because JSON feels inefficient - 6 characters (worst case) to transfer 2 bytes of data. And the communication wasn't really happy at 160ms intervals :/

    My questions:

    • any better solution than the "UART" between a browser and and nRF?
    • any better serialization format for Uint16 array? Current idea: convert to hex, transfer without separator, and reassemble from 4 byte chunks. That's roughly 2/3 data usage compared to JSON, not sure about the CPU usage. And 😴
    • I guess bluetooth layer itself takes care about data integrity & ordering. Right? :) Or should I add my own CRC or other error check?
  • any better solution than the "UART" between a browser and and nRF?

    Not really - you can create your own characteristics, but because the UART is handled natively by Espruino it will probably be slightly faster.

    any better serialization format for Uint16 array?

    Raw binary :) I think just Bluetooth.write(uint16array.buffer) should do it, then you can decode on the other end.

    Bluetooth LE packets are normally 20 bytes max, so if you can send in chunks that are multiples of 20 you're likely to get slightly better bandwidth.

    Also do NRF.setConnectionInterval(7.5) as this'll force high speed comms all the time (usually Espruino drops it after some inactivity).

    I guess bluetooth layer itself takes care about data integrity & ordering.

    Absolutely yes :)

  • Oh, best serialization is no serialization at all :)

    Current progress: pretty happily pushing 128 * 16 bit values at 100ms intervals, and that is more than enough for this project.
    Thanks Gordon!

    For the record, going below 100ms interval, the busy LED becomes almost always on, and the actual throughput doesn't increase (measured in the browser by the number of received "packets").

    Edit: doing some math :)
    Theoretical maximum data transfer: (1000 ms /7.5 7.5ms interval)* 20 byte packets = 2666 bytes / sec
    Measured maximum: 260 bytes * 10 times per second = 2600 bytes / sec
    Is this pretty damn close to the theoretical maximum? :)

  • That sounds about right, yes :)

    At some point I believe we could enable a larger MTU (eg >20 byte chunks) which would really improve matters, but it's not guaranteed it won't just fall back to 20... So you could create something that'd work on one computer but bomb on another - and that sounded like a support nightmare :)

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

"Streaming" data from MDBT42 via bluetooth

Posted by Avatar for AkosLukacs @AkosLukacs

Actions