Weird Values from BT LE

Post questions and issues with Concept2 PM3 SDK

Weird Values from BT LE

Postby JamesRocheUK » July 30th, 2015, 7:34 am

I am getting weird number from my PM5 via Bluetooth, i am getting an update on 0x0031 but the duration never goes up, the elapsed time and distance are very odd also. Sample below.

Elapsed Time lo:234
Elapsed Time Mid:123
Elapsed Time High:0

Distance lo: 44
distance Mid: 23
Distance High: 0

Duration low: 0
Duration Mid: 0
duration High: 0

While the PM5 screen shows the following
Time 5:17
Distance 593

Everything else looks to be coming through correctly... Am i missing the point here? Should for example Elapsed time high/mid/low be hours:minutes:seconds? What do the values coming from tend vice actually mean? do they look correct?

Much appreciated!
Posts: 3
Joined: July 30th, 2015, 7:28 am

Weird Values from PM5 over BT:LE

Postby JamesRocheUK » July 30th, 2015, 7:50 am

I am getting strange values from Bluetooth LE when reading 0x0031, The packets gives me this for Time Elapsed

Lo: 234
Mid 123
high: 0

When my PM5 screen shows duration of 5:17

What do the Low, Med, High value represent? Do i need to :normalise" them in some way?
Posts: 3
Joined: July 30th, 2015, 7:28 am

Re: Weird Values from BT LE

Postby Piboo » July 31st, 2015, 12:50 pm


You receive a byte array from PM5 so Lo, Mid and Hi corresponds to a byte hence 8 bits.

So you must rebuild your elapsed Time value like this:
elapseTime = Hi * 65536 + Mid * 256 + Lo

The results is in 0.01s

You can find some good explanation about byte / bits conversion.

Posts: 12
Joined: April 7th, 2015, 6:33 pm

Re: Weird Values from BT LE

Postby horseshoe7 » August 5th, 2015, 11:46 am

You can also read the 3 bytes into a uint32, where

Byte 4 3 2 1
-- hi mid lo

In Objective-C, this was done by:

Code: Select all
NSData *data = ... // the bytes coming from the characteristic
uint32_t time = 0;  // initialize to zero so that all bits of a unit32_t are initialized to 0
[data getBytes:&time range:NSMakeRange(0, 3)];  // 3 because the spec says 3 bytes for elapsed time
NSTimeInterval elapsed = (NSTimeInterval)time * 0.01;  // 0.01 because the spec says this uint32_t value has a unit of 0.01s
Posts: 15
Joined: April 21st, 2015, 6:28 am

Re: Weird Values from BT LE

Postby wivku » August 9th, 2015, 12:13 pm

The Hi * 65536 + Mid * 256 + Lo is fine, but specific for hi-mid-lo. In another situation it could be you have 2 bytes (LSB,MSB).

Similar to horseshoe7's answer, in Swift:

Code: Select all
var testdata = NSData(bytes: [234,123,0, 33,11,0] as [UInt8], length: 6) // example: first 6 bytes from 0x0031

var elapsed: Int = 0
testdata.getBytes(&elapsed, range: NSMakeRange(0, 3)) // elapsed time starts at byte 0 and is 3 bytes long

print( Double(elapsed) * 0.01 ) // documentation states it is in 0.01 seconds, so multiply by 0.01 to get seconds
// = 317.22 seconds = 5:17

Or a more generic solution (this time in JavaScript)

Code: Select all
function bytesToNumber(bytes) {
   var total=0;
   for (var i=0; i< bytes.length; i++) {
      total += (bytes[i] * Math.pow(256, i));
   return total;

var elapsed = bytesToNumber( [234,123,0] );
console.log( elapsed * 0.01 ); // 317.22
Posts: 6
Joined: December 19th, 2014, 12:03 pm

Return to SDK Questions

Who is online

Users browsing this forum: No registered users and 1 guest