Author Topic: Tilting Trigger on the Accelerometer  (Read 1202 times)

SK

  • Newbie
  • *
  • Posts: 18
    • View Profile
Re: Tilting Trigger on the Accelerometer
« Reply #15 on: February 27, 2017, 04:41:08 pm »
Thank you. I managed to fix the undefined error.

I'll run some tests with it and figure out the range and values.

This is the raw data I get on sigfox: 23.png

I'm using a online hex conversion website (http://www.scadacore.com/field-applications/programming-calculators/online-hex-converter/) to test if my losant values are correct: 24.png

Nick_W

  • Full Member
  • ***
  • Posts: 214
    • View Profile
Re: Tilting Trigger on the Accelerometer
« Reply #16 on: February 27, 2017, 05:40:47 pm »
You're decoding the float wrong. The floats are 4 bytes little endian.

What you get is:
1 byte (0x08) - which decodes as 8
4 bytes of integer (0x02000000) - which decodes as 2
4 bytes of float (0x6f12833c) - which decodes as 0.016

1 byte (0x08) - which decodes as 8
4 bytes of integer (0x01000000) - which decodes as 1
4 bytes of float (0x250681bf) - which decodes as -1.008

1 byte (0x08) - which decodes as 8
4 bytes of integer (0x00000000) - which decodes as 0
4 bytes of float (0xa69b443d) - which decodes as 0.048

Exactly as expected.

You were putting three bytes of 0x00 before the float to decode. Remember byte = 1 bytes, integer = 4 bytes, float = 4 bytes - total 9 bytes.