This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Best way to send float over BLE

What is the Best way to send float over BLE?

Values range between -2.000volt and +2.000Volt (-2000mV / +2000mV) Do I break it into two uint8_t and manipulate the +/- sign in separate 8-bit byte?

I took the ble_sdk_app_proximity example, and commented out what I do not need. Then used the examples from the tutorials, to add three services. So I added x3 services, based on the BLE Characteristics, a beginner's tutorial, and it is working fine. (nrf5-ble-tutorial-characteristic-CompletedCode ported for SDK 13.zip)

So I need to send the Voltage either as a float, or manipulate it to look like uint8_t, and keep track of the sign.

Any help appreciated.

Parents
  • Hi. Normally there are no floats in digital system. Unless you really really really need to work with that because of sealed protocol specification just use native representation of that "type", transport it and represent only on the final system where it needs to appear as float (GUI of mobile app, back end API/database...)

    So you get voltage as some digital sample of certain bit length (e.g. 14-bit sample by SAADC peripheral on nRF52), probably align it to next 8-bit byte (because BLE Link layer or any higher protocol is byte-oriented) and just send it to the other side.

  • @awneil I was not precise. What I meant is that "float" is just interpretation during arithmetic. Unless you do such manipulations (and there is normally no reason to do it) there is no difference between float and int, just bunch of bytes. Also what I meant by "no float in digital system" is that normally there is no natural way of "creating" floats in digital system, there is simple A2D conversion which results in some sample with given bit-length, interpreting it as float doesn't (normally) make sense unless you want to display it to humans or unless some very specific algorithm demands that instead of working on "raw" data (which are obvious integer). But I'm keen to learn if my experience is false and there are some legit and "natural" uses of floats during signal or other processing.

Reply
  • @awneil I was not precise. What I meant is that "float" is just interpretation during arithmetic. Unless you do such manipulations (and there is normally no reason to do it) there is no difference between float and int, just bunch of bytes. Also what I meant by "no float in digital system" is that normally there is no natural way of "creating" floats in digital system, there is simple A2D conversion which results in some sample with given bit-length, interpreting it as float doesn't (normally) make sense unless you want to display it to humans or unless some very specific algorithm demands that instead of working on "raw" data (which are obvious integer). But I'm keen to learn if my experience is false and there are some legit and "natural" uses of floats during signal or other processing.

Children
No Data
Related