Android Question BLE2 TI Sensor Tag CC2650

Wolli013

Well-Known Member
Licensed User
Longtime User
Hi all,
can you help me for convert Code to B4A?


void sensorHdc1000Convert(uint16_t rawTemp, uint16_t rawHum,
float *temp, float *hum)
{
//-- calculate temperature [°C]
*temp = ((double)(int16_t)rawTemp / 65536)*165 - 40;

//-- calculate relative humidity [%RH]
rawHum &= ~0x0003; // remove status bits
*hum = ((double)rawHum / 65536)*100;
}
 

Wolli013

Well-Known Member
Licensed User
Longtime User
Last edited:
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
This ist my Code and running verry good.
If humidity > 50% then value wrong!
humidity are -47,68 and smaler.



B4X:
Public Sub writeData1
   
 'Enable Temperatur und Feuchtresensor
    manager.SetNotify("f000aa20-0451-4000-b000-000000000000","f000aa21-0451-4000-b000-000000000000",True)
    Log("Set Notify")
    Sleep(500)
   
    Dim valoriByte(1) As Byte
    valoriByte(0)=0x01
    manager.WriteData("f000aa20-0451-4000-b000-000000000000","f000aa22-0451-4000-b000-000000000000",valoriByte)
    Log("Set WriteData1")  
    Sleep(500)

    Dim valoriByte(1) As Byte 'Period
    valoriByte(0)=0xFF
    manager.WriteData("f000aa20-0451-4000-b000-000000000000","f000aa23-0451-4000-b000-000000000000",valoriByte)
    Log("Set WriteData2")  
    Sleep(500)  
    'Period AA23* R/W  2.55 sec (0xFF). Default 1 second (0x64).
 
End Sub

Sub Manager_DataAvailable (ServiceId As String, Characteristics As Map)
 
        Private tem As Int
        Private hum As Int
        Private temp1,temp2,hum1 As Float
        Dim ArrayBytes() As Byte = Characteristics.Get("f000aa21-0451-4000-b000-000000000000")

'Dim bc As ByteConverter
'bc.LittleEndian = True
'Dim temp As Float = bc.ShortsFromBytes(Array As Byte(ArrayBytes(0), ArrayBytes(1)))(0)/65536*165-40
'Log(temp)
'Dim temp10 As Float = bc.ShortsFromBytes(Array As Byte(ArrayBytes(2), ArrayBytes(3)))(0)/65536*100
'Log(temp10)
 
        'tem = ArrayBytes(0) + (ArrayBytes(1) * 256)
        tem = (ArrayBytes(1)*256) + ArrayBytes(0)
       
        Sleep(500)  
        'hum = ArrayBytes(2) + (ArrayBytes(3) * 256)
        hum = (ArrayBytes(3)*256) + ArrayBytes(2)
 
        temp1 = (tem/65536)*165-40
 
        temp2 = ((temp1*9.0)/5.0)+32.0 ' = Fahrenheit
        Log("Temperatur-Grad = " & NumberFormat(temp1, 1, 2))
        Log("Temperatur-Fahrenheit = " & NumberFormat(temp2, 1, 2))
 
        hum1 = (hum/65536)*100  
 
        Log("Feuchte = " & NumberFormat(hum1, 1, 2))
 
         BlueATemperatur = NumberFormat(temp1, 1, 2) 'Übergabedaten
         BlueALuftfeuchtigkeit = NumberFormat(hum1, 1, 2) 'Übergabedaten
       


'Gefundenen Code----------------------------------------------------------------------------------------
' Calculate the humidity temperature (Celsius).
'var tData = evothings.util.littleEndianToInt16(data, 0)
'var tc = -46.85 + 175.72 / 65536.0 * tData
'' Calculate the relative humidity.
'var hData = (evothings.util.littleEndianToInt16(data, 2) & ~0x03)
'var h = -6.0 + 125.00 / 65536.0 * hData        
 
End Sub
 
Upvote 0

Wolli013

Well-Known Member
Licensed User
Longtime User
Hello, unfortunately, it does not go.
The value should lie about 20 degrees and with approx. 28-30%.

Log:

Feuchte = 0.18
Temperatur-Grad = -39.79
Temperatur-Fahrenheit = -39.62
Feuchte = 0.08
Temperatur-Grad = -39.79
Temperatur-Fahrenheit = -39.62
Feuchte = 0.37
Connected: CC2650 SensorTag
Temperatur-Grad = -39.8
Temperatur-Fahrenheit = -39.64
Feuchte = 0.28
Temperatur-Grad = -39.78
Temperatur-Fahrenheit = -39.6
Feuchte = 0.18
Temperatur-Grad = -39.78
Temperatur-Fahrenheit = -39.6
Feuchte = 0.09
Temperatur-Grad = -39.79
Temperatur-Fahrenheit = -39.62
Feuchte = 0.38
Connected: CC2650 SensorTag
Temperatur-Grad = -39.78
Temperatur-Fahrenheit = -39.6
Feuchte = 0.28
Temperatur-Grad = -39.78
Temperatur-Fahrenheit = -39.6
Feuchte = 0.19
Temperatur-Grad = -39.76
Temperatur-Fahrenheit = -39.56
Feuchte = 0.09
Temperatur-Grad = -39.78
Temperatur-Fahrenheit = -39.6
Feuchte = 0.38
Connected: CC2650 SensorTag
Temperatur-Grad = -39.78
Temperatur-Fahrenheit = -39.6
Feuchte = 0.29
Temperatur-Grad = -39.78
Temperatur-Fahrenheit = -39.6
Feuchte = 0.29
Temperatur-Grad = -39.76
Temperatur-Fahrenheit = -39.56
Feuchte = 0.19
 
Upvote 0
Top