iOS Question iBLE HealtThermometer (solved)

f0raster0

Well-Known Member
Licensed User
Longtime User
How can I get the temperature in decimal?
it should be between 36°C to 39°C

B4X:
sub Healt_Thermometer(Characteristics As Map)      
    For Each id As String In Characteristics.Keys   
        If id = "2A1C" Then     'Temperature                       
            Dim ArrayBytes () As Byte = Characteristics.Get(id)
            Dim bc As ByteConverter
            Log("Temp Hex: "&bc.hexFromBytes(Characteristics.Get(id)))           
            Log("Temp2: "&ArrayBytes(id))
       end if
End sub

my logs:
 

f0raster0

Well-Known Member
Licensed User
Longtime User
Thanks Erel,

The temperature measurement value is a float,
Could your example work for the temperature of the health thermometer,
if yes could you please help me with an example.

 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
B4X:
Dim temp As Float = bc.FloatsFromBytes(Array As Byte(ArrayBytes(1), ArrayBytes(2), ArrayBytes(3), ArrayBytes(4)))(0)

Thanks Erel, what I'm doing wrong?

B4X:
Sub Healt_Thermometer(Characteristics As Map)  

  
    For Each id As String In Characteristics.Keys  
        If id = "2A1C" Then          
            Dim ArrayBytes () As Byte = Characteristics.Get(id)
            Dim bc As ByteConverter
            Dim temp As Float = bc.FloatsFromBytes(Array As Byte(ArrayBytes(1), ArrayBytes(2), ArrayBytes(3), ArrayBytes(4)))(0)
            Log($"TestVal: ${temp}"$)
            End If  
    Next
End Sub
 
Upvote 0

f0raster0

Well-Known Member
Licensed User
Longtime User
The correct temperature should be for example: 39.4°C or 37.92°C (values between 37°C and 39°C )

B4X:
Sub Healt_Thermometer(Characteristics As Map)     
    For Each id As String In Characteristics.Keys   
        If id = "2A1C" Then   
            Log("Temp Hex: "&bc.hexFromBytes(Characteristics.Get("2A1C")))               
            Dim ArrayBytes () As Byte = Characteristics.Get("2A1C")
            Dim temp As Float = bc.FloatsFromBytes(Array As Byte(ArrayBytes(1), ArrayBytes(2), ArrayBytes(3), ArrayBytes(4)))(0)
            Log($"TestVal: ${temp}"$)
        End If
    Next

 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I think I found it.

This code returns good results (temp * 100):
B4X:
  bc.LittleEndian = True
   Log(bc.ShortsFromBytes(bc.HexToBytes("AC0E"))(0))   
   Log(bc.ShortsFromBytes(bc.HexToBytes("880E"))(0))   
   Log(bc.ShortsFromBytes(bc.HexToBytes("680E"))(0))   
   Log(bc.ShortsFromBytes(bc.HexToBytes("8C0E"))(0))   
   Log(bc.ShortsFromBytes(bc.HexToBytes("B00E"))(0))   
   Log(bc.ShortsFromBytes(bc.HexToBytes("D40E"))(0))   
   Log(bc.ShortsFromBytes(bc.HexToBytes("F80E"))(0))   
   Log(bc.ShortsFromBytes(bc.HexToBytes("1C0F"))(0))   
   Log(bc.ShortsFromBytes(bc.HexToBytes("400F"))(0))   
   Log(bc.ShortsFromBytes(bc.HexToBytes("640F"))(0))   
   Log(bc.ShortsFromBytes(bc.HexToBytes("840F"))(0))

B4X:
bc.LittleEndian = True
Dim temp As float = bc.ShortsFromBytes(Array As Byte(ArrayBytes(1), ArrayBytes(2))(0) / 100
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…