CodingDecode some data

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  ANT_THOMAS  
 To:  ALL
42633.1 
I've built some wireless temperature sensors which work fine on my current setup, but I'm looking to improve it. Without going into all the boring details, I have some data I need to manually decode.

This data contains a float, long and char*.
I've figured out the long and char and need to decode the float. Ideally in a bash script since that's how I'm currently working

Some examples of the payload data and the known actual values.

Payload : 0, 0, 108, 65, 60, 16, 0, 0, 97, 0
temp=14.75
bat=4156
adr=a

Payload : 0, 0, 63, 65, 30, 16, 0, 0, 111, 0
temp=11.94
bat=4126
adr=o

Payload : 0, 0, 157, 65, 98, 19, 0, 0, 98, 0
temp=19.62
bat=4962
adr=b

Payload : 0, 0, 144, 65, 208, 17, 0, 0, 108, 0
temp=18.00
bat=4560
adr=l


And my decoding so far of the first example

Payload : 0, 0, 108, 65, 60, 16, 0, 0, 97, 0
char = adr = a

Payload : 0, 0, 108, 65, 60, 16, 0, 0, 97, 0
long 8bit to 16bit
(16 x 256) + 60 = 4156
bat=4156
edit - made an error here

Payload : 0, 0, 108, 65, 60, 16, 0, 0, 97, 0
I need to decode this to the temp 14.75 float value.

Any ideas?
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS     
42633.2 In reply to 42633.1 
What makes you think the 65 in position 4 should be used for both bat and temp?

And how certain are you of those example numbers?

Because 144 = 18 * 8 - which seems very coincidental, especially combined with 157 / 8 giving 19.625, but that doesn't work for the first two examples...

However, 14.75 * 8 is 118 - a single digit out. I don't see anything similar for 11.94 and 63

0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Peter (BOUGHTONP)     
42633.3 In reply to 42633.2 
I got that massively wrong up there - have edited.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS     
42633.4 In reply to 42633.3 
So the other numbers are definitely all correct?

How does the data actually come in - presumably it's either binary or hex encoded rather than decimals?

Shouldn't the sensor provide documentation of the format? (Or does it expect using its own crappy software?)

0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Peter (BOUGHTONP)     
42633.5 In reply to 42633.2 
I have now figured it out, kinda.
So it seems the temps are 3dp and there has been some rounding which put me off the scent a bit.
The encoding is IEEE 754

And goes as follows

0, 0, 108, 65, 60, 16, 0, 0, 97, 0

In binary
65 = 01000001
108 = 01101100

Then put that in a suitable sequence for IEEE 754 with 0 padding at the end
01000001 01101100 00000000 00000000

That converts to 14.75.

Just need to do the binary to IEEE 754 floating point number in bash somehow, or at least called from a bash script now I have the binary numbers in bash.
 
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  ANT_THOMAS     
42633.6 In reply to 42633.5 
Also, the leading zeros in the array may be the padding at the end, as some other examples contain "128" at place 2, so I think I need to include them. But that's easy enough.
0, 0, 108, 65
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Peter (BOUGHTONP)     
42633.7 In reply to 42633.4 
Numbers are correct, as I've now manually successfully decoded it.
In terms of documentation, I've made and coded these sensors myself, I just didn't entirely understand how the data was encoded with the library (RadioHead ASK).

Now just need to figure out a command line binary to IEEE 754 floating point number conversion.
0/0
 Reply   Quote More 

 From:  Peter (BOUGHTONP)  
 To:  ANT_THOMAS     
42633.8 In reply to 42633.7 
Bash doesn't do floating point, but I still expected it to be a simple case of calling bc or something, but nothing useful comes up from relevant searches.

Guess you'll have to convert your manual steps to Perl or Python?

0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  Peter (BOUGHTONP)     
42633.9 In reply to 42633.8 
Yeah, seen similar. Was wanting to use bc. Now looking at some other simple programs, C++, Perl or Python should handle it, then feed it back in.
0/0
 Reply   Quote More 

 From:  ANT_THOMAS  
 To:  ALL
42633.10 
Done, decoded using some simple python.
0/0
 Reply   Quote More 

Reply to All    
 

1–10

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2020 Project Beehive Forum

Forum Stats