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

How to interpret value from custom characteristic

Hello

I made a custom service with characteristic. It send the number 1234 over ble. When i open the Master Control Panel and look at the custom characteristic. I read a value of (0x) 01-D2-04. How can i get a decimal value that's unstable?

image description

Hope someone has more info.

Nick

Parents
  • 1234 = 0x04D2, I'm assuming you sent the leading 0x01 yourself as part of the message data, so you have exactly what you need. It's just your integer in hexadecimal

  • You're just sending data, there is no 'sending it in decimal' it's just 16 bits which represent an integer and hexadecimal and decimal are just two ways of writing down the value of that number, or you can write it in binary. So if you are going to send a number by putting it in a buffer and sending it out as two bytes, then the receiving app needs to put those back into a number by receiving and processing two bytes (two little-endian bytes in this case) and turning them back into the same number represented on the app side, in this case the number is 256 * byte[1] + byte[0].

    If you look at the spec for the HRM service (developer.bluetooth.org/.../CharacteristicViewer.aspx you'll see the data format is defined, the HRM app interprets it.

Reply
  • You're just sending data, there is no 'sending it in decimal' it's just 16 bits which represent an integer and hexadecimal and decimal are just two ways of writing down the value of that number, or you can write it in binary. So if you are going to send a number by putting it in a buffer and sending it out as two bytes, then the receiving app needs to put those back into a number by receiving and processing two bytes (two little-endian bytes in this case) and turning them back into the same number represented on the app side, in this case the number is 256 * byte[1] + byte[0].

    If you look at the spec for the HRM service (developer.bluetooth.org/.../CharacteristicViewer.aspx you'll see the data format is defined, the HRM app interprets it.

Children
No Data
Related