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:
characteristic: 2A1C

Temp Hex: 06B00E00FEDC070C050B092704
Temp2: 14
Temp Hex: 06D40E00FEDC070C050B0A0604
Temp2: 14
Temp Hex: 06F80E00FEDC070C050B0A2104
Temp2: 14
Temp Hex: 061C0F00FEDC070C050B0B0004
Temp2: 15
Temp Hex: 06400F00FEDC070C050B0B1B04
Temp2: 15
Temp Hex: 06640F00FEDC070C050B0B3604
Temp2: 15
Temp Hex: 06840F00FEDC070C050B0C1504
Temp2: 15
Temp Hex: 06600F00FEDC070C050B0C3004
Temp2: 15
Temp Hex: 063C0F00FEDC070C050B0D0F04
Temp2: 15
Temp Hex: 06180F00FEDC070C050B0D2A04
Temp2: 15
Temp Hex: 06F40E00FEDC070C050B0E0904
Temp2: 14
 

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.

Dim b() As Byte = Characteristics.Get("2A1C")
Dim hrLength As Int = 1 + Bit.UnsignedShiftRight(b(0), 7)
Dim rate As Int
If hrLength = 1 Then
rate = Bit.And(0xff, b(1))
Else
Dim r() As Byte = Array As Byte(b(1), b(2))
rate = bc.IntsFromBytes(r)(0)
'rate = bc.FloatsFromBytes(r)(0)
rate = bc.IntsFromBytes(r)(0)

End If
Log($"Rate: ${rate}"$)
 
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?
Notification state changed for characteristic: 2A1C
TestVal: 2.682377e+24
TestVal: -5.166071e-10
TestVal: -2.439608e+12
TestVal: -1.152072e+34
TestVal: 4.731601e-22
TestVal: 2.234436
TestVal: 1.055182e+22
TestVal: -1.681002e-36
TestVal: 4.121806e+19
TestVal: 0.008728264
TestVal: 1.848282e-24
TestVal: -4.500282e+31
TestVal: -9.529719e+09
TestVal: -2.017996e-12
TestVal: -4.273274e-34
TestVal: 2.682377e+24
TestVal: -1.093958e-31
TestVal: -5.166071e-10

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

Notification state changed for characteristic: 2A1C

Temp Hex: 06AC0E00FEDC070C050B1B0304
TestVal: -2.017996e-12

Temp Hex: 06880E00FEDC070C050B1B1E04
TestVal: -4.273274e-34

Temp Hex: 06680E00FEDC070C050B1B3904
TestVal: 2.682377e+24

Temp Hex: 068C0E00FEDC070C050B1C1804
TestVal: -1.093958e-31

Temp Hex: 06B00E00FEDC070C050B1C3304
TestVal: -5.166071e-10

Temp Hex: 06D40E00FEDC070C050B1D1204
TestVal: -2.439608e+12

Temp Hex: 06F80E00FEDC070C050B1D2D04
TestVal: -1.152072e+34

Temp Hex: 061C0F00FEDC070C050B1E0C04
TestVal: 4.731601e-22

Temp Hex: 06400F00FEDC070C050B1E2704
TestVal: 2.234436

Temp Hex: 06640F00FEDC070C050B1F0604
TestVal: 1.055182e+22

Temp Hex: 06840F00FEDC070C050B1F2104
TestVal: -1.681002e-36
 
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
Top