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
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)
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
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