German BLE2 TI Sensor Tag

Wolli013

Well-Known Member
Licensed User
Longtime User
Hallo Leute, wer arbeitet mit einem TI Sensor Tag und kann mir ein paar Tips geben, wie ich die ausgelesenen Daten weiter verarbeiten kann um brauchbare Werte zu erhalten?
Bluetooth ist für mich ziemlich neu und irgendwie komme ich nicht weiter.

Ich nutze BLE2 vo Erel, hier die Daten die ich beim auslesen erhalte.

Name: CC2650 SensorTag
Zusatzdaten: (MyMap) {1=[B@901a390, 2=[B@6e8b489, -1=[B@30ccc8e, 9=[B@69a8caf, 18=[B@50568bc, 10=[B@69f1045, 0=[B@30d239a}

05
80AA
0D00030000
4343323635302053656E736F72546167
08002003
00
020105030280AA06FF0D0003000011094343323635302053656E736F72546167051208002003020A00000000000000000000000000000000000000000000

Was kann ich nun damit angangen?
Vielen Dank im vorraus.
 

Wolli013

Well-Known Member
Licensed User
Longtime User
Hier der Code aus der Starter Datei

B4X:
#Region  Service Attributes
    #StartAtBoot: False
    #ExcludeFromLibrary: True
#End Region

Sub Process_Globals
    Public manager As BleManager2
    Public currentStateText As String = "UNKNOWN"
    Public currentState As Int
    Public connected As Boolean = False
    Public ConnectedName As String
    Private ConnectedServices As List
    
    Private bc As ByteConverter
    Private hex1, hex2, hex3, hex4, hex5, hex6, hex7 As String
End Sub

Sub Service_Create
    manager.Initialize("manager")
    
End Sub

Sub Service_Start (StartingIntent As Intent)

End Sub

Public Sub Scan
    manager.Scan(Null) 'alle Geräte scannen

'Dim oUUID As List 'Aus Liste scannen
'   oUUID.Initialize
'   oUUID.Add("00002902-0000-1000-8000-00805f9b34fb")
'   manager.Scan(oUUID)
 
End Sub
 
Public Sub ReadData
    For Each s As String In ConnectedServices
        manager.ReadData(s)
        'manager.ReadData2(s, "00002a28-0000-1000-8000-00805f9b34fb")
    Next
    
End Sub

Public Sub Disconnect
    manager.Disconnect
End Sub

Sub Manager_StateChanged (State As Int)
    Select State
        Case manager.STATE_POWERED_OFF
            currentStateText = "POWERED OFF"
        Case manager.STATE_POWERED_ON
            currentStateText = "POWERED ON"
        Case manager.STATE_UNSUPPORTED
            currentStateText = "UNSUPPORTED"
    End Select
    currentState = State
    CallSub(Main, "StateChanged")
End Sub

Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
 
Log("Name: " & Name)
Log("Mac Adresse: " & Id)
Log("RSSI: " & RSSI)
Log("Zusatzdaten: " & AdvertisingData)
 
Dim data1() As Byte = AdvertisingData.Get(1)
Dim data2() As Byte = AdvertisingData.Get(2)
Dim data3() As Byte = AdvertisingData.Get(-1)
Dim data4() As Byte = AdvertisingData.Get(9)
Dim data5() As Byte = AdvertisingData.Get(18)
Dim data6() As Byte = AdvertisingData.Get(10)
Dim data7() As Byte = AdvertisingData.Get(0)

'you can use byte converter to convert to hex if you like:
Dim bc As ByteConverter
Log(bc.HexFromBytes(data1))
Log(bc.HexFromBytes(data2))
Log(bc.HexFromBytes(data3))
Log(bc.HexFromBytes(data4))
Log(bc.HexFromBytes(data5))
Log(bc.HexFromBytes(data6))
Log(bc.HexFromBytes(data7))

    hex1 = bc.HexFromBytes(data1)
    hex2 = bc.HexFromBytes(data2)
    hex3 = bc.HexFromBytes(data3)
    hex4 = bc.HexFromBytes(data4)
    hex5 = bc.HexFromBytes(data5)
    hex6 = bc.HexFromBytes(data6)
    hex7 = bc.HexFromBytes(data7)
 
    Entzifferung(hex1)
    Entzifferung(hex2)
    Entzifferung(hex3)
    Entzifferung(hex4)
    Entzifferung(hex5)
    Entzifferung(hex6)
    Entzifferung(hex7)
 
    ConnectedName = Name
    manager.StopScan
    manager.Connect(Id)
 
End Sub

Sub PrintCharProperties(Characteristic As String, Properties As Int)
   Log($"${Characteristic} Properties:"$)
   Dim props As Map = CreateMap(1: "Broadcast", 2: "Read", 4: "WriteWithoutResponse", 8: "Write", _
     0x10: "Notify")
   For Each key As Int In props.Keys
     If Bit.And(Properties, key) <> 0 Then Log(props.Get(key))
   Next
End Sub

Sub Manager_DataAvailable (ServiceId As String, Characteristics As Map)

    For Each c As String In Characteristics.Keys
     PrintCharProperties(c, manager.GetCharacteristicProperties(ServiceId, c))
   Next

   Dim bc As ByteConverter
   Dim KeyCode As String

For Each id As String In Characteristics.Keys
     KeyCode = Characteristics.Get(id)
     Log("KeyCode=" & KeyCode)
     Log( bc.HexFromBytes( Characteristics.Get(id) ) )
Next

    For Each id As String In Characteristics.Keys 
        
           For Each id As String In Characteristics.Keys
             KeyCode = Characteristics.Get(id)
             Log("keyCode=" & KeyCode&" Hex: "&bc.HexFromBytes(Characteristics.Get(id)))
             Log("STR: " & bc.StringFromBytes(Characteristics.Get(id),"UTF-8"))           
           Next
 
    Next
 
   Dim bc As ByteConverter
    Log(Characteristics)
'   

    For i = 0 To Characteristics.Size - 1
        Dim data1() As Byte =  Characteristics.GetValueAt(i)
        Log("CHR: " & Characteristics.GetKeyAt(i))
        Log("VAL: " & Characteristics.GetValueAt(i))
        Log("HEX: " & bc.HexFromBytes(data1))
        Log("STR: " & bc.StringFromBytes(data1,"UTF-8"))
    Next


    For Each key As String In Characteristics.Keys
        Dim b() As Byte = Characteristics.Get(key)
        Log(key & ": " & bc.HexFromBytes(b))
    Next

For Each id As String In Characteristics.Keys
 Dim Value() As Byte = Characteristics.Get(id)
 Log($"id=${id}, value=${BytesToString(Value, 0, Value.Length, "UTF8")}"$)
Next
    
    CallSub3(Main, "DataAvailable", ServiceId, Characteristics)
End Sub

Sub Manager_Disconnected
    Log("Disconnected")
    connected = False
    CallSub(Main, "StateChanged")
End Sub

Sub Manager_Connected (services As List)
    Log("Connected")
    connected = True
    ConnectedServices = services
    CallSub(Main, "StateChanged")
End Sub

Sub Manager_RssiAvailable (Success As Boolean, RSSI As Double)
   Log(Success)
   Log(RSSI)
End Sub

'Return true to allow the OS default exceptions handler to handle the uncaught exception.
Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub

Sub Service_Destroy

End Sub

Private Sub Entzifferung(hex As String)
    Private i, j As Int
    Private ch, txt As String
    
    For i = 0 To hex.Length - 1 Step 2
        ch = hex.SubString2(i, i + 2)
        Dim Bytes() As Byte
        Bytes = bc.HexToBytes(ch)
        j = Bytes(0)
        txt = txt & Chr(j)
    Next
    Log("Entzifferung " &txt)
End Sub
 

Wolli013

Well-Known Member
Licensed User
Longtime User
Hier ist jetzt der Hauptcode für Temperatur und Luftfeuchte zum auslesen.
Nur die Erebnisse sind sehr seltsam und ergeben noch keinen Sinn.

B4X:
 Dim bc As ByteConverter
    For Each id As String In Characteristics.Keys  
       
        If id = "f000aa21-0451-4000-b000-000000000000" Then  
            Log("Temp Hex: "&bc.hexFromBytes(Characteristics.Get("f000aa21-0451-4000-b000-000000000000")))              
            Dim ArrayBytes() As Byte = Characteristics.Get("f000aa21-0451-4000-b000-000000000000")
            Dim temp As Float = bc.FloatsFromBytes(Array As Byte(ArrayBytes(0), ArrayBytes(1), ArrayBytes(2), ArrayBytes(3)))(0)
 
            Log($"TestVal: ${temp}"$)
           
           Dim te1 As String = ArrayBytes(0)
           Log("te1 " & te1)
           Dim te2 As String = ArrayBytes(1)
           Log("te2 " & te2)
           Dim te3 As String = ArrayBytes(2)
           Log("te3 " & te3)
           Dim te4 As String = ArrayBytes(3)
           Log("te4 " & te4)
 
        End If
    Next


Nur weis ich noch nicht wie ich die Werte richtig verarbeiten kann.
Anbei auch mal der OrginalCode von der TI Seite.

Humidity Sensor
The humidity sensor used on the SensorTag is HDC1000 from Texas Instruments. The humidity sensor is implemented with the following source code files:
Application: sensortag_hum.c
Driver: SensorHdc1000.c
Profile: humidityservice.c

Humidity Sensor
Type UUID Access Size (bytes) Description
Data AA21* R/N 4 Temp[0:7], Temp[8:15], Hum[0:7], Hum[8:15]
Notification 2902 R/W 2 Write 0x0001 to enable notifications, 0x0000 to disable.
Configuration AA22* R/W 1 Write 0x01 to enable data collection, 0x00 to disable.
Period AA23* R/W 1 Resolution 10 ms. Range 100 ms (0x0A) to 2.55 sec (0xFF). Default 1 second (0x64).
Configuration
When an enable command (0x01) is written to the configuration characteristic, the sensor starts to perform measurements each second and the data is stored in the data characteristic. When the disable command (0x00) is issued, the sensor's measurement cycle is stopped, the data are cleared and no longer reported.

Data
The data from the humidity sensor consists of two 16-bit unsigned integers: the temperature in bytes 0 and 1, and the pressure in bytes 2 and 3. Conversion to temperature and relative humidity is done as shown below. The temperature unit is degrees Celsius (°C), the humidity unit is relative humidity (%RH).

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
Hier mal die Log Ergebnisse
Vielleicht kann ja jemand helfen

Name: CC2650 SensorTag
Mac Adresse: CC:78:AB:7F:7D:82
RSSI: -53
Zusatzdaten: (MyMap) {1=[B@11e1f2e, 2=[B@2e77acf, -1=[B@f148c5c, 9=[B@9abfb65, 18=[B@9f1003a, 10=[B@8af4eb, 0=[B@a8c1248}
Discovering services.
Connected
retries: 4
Setting descriptor. Success = true
writing descriptor: true

Temp Hex: F061583B
TestVal: -2.7896317E29
te1 -16
te2 97
te3 88
te4 59
Temp Hex: F861183B
TestVal: -1.8261848E34
te1 -8
te2 97
te3 24
te4 59
Temp Hex: F061DC3A
TestVal: -2.7960146E29
te1 -16
te2 97
te3 -36
te4 58
Temp Hex: F0619C3A
TestVal: -2.7929197E29
te1 -16
te2 97
te3 -100
te4 58
Temp Hex: F8615C3A
TestVal: -1.8283396E34
te1 -8
te2 97
te3 92
 

pucki

Active Member
Licensed User
Longtime User
Ist doch nach deiner Anleitung ganz einfach.

Du schneidest den Hex-Wert in 2 Teile ;)

Temp Hex: F061 *schniep* 583B

F061 hex = ( ( (61537 dez / 65636) * 165 ) - 40 ) Allerdings ist in der Anleitung ein Fehler denke ich. Es sind Fahrenheit NICHT Grad Celsius


583B hex = ( ( 22587 dez / 65635 ) * 100 ) = Luftdruck.

Ich kann mich aber auch irren.

Ach und noch was. So Abfragen macht man immer in einer Schleife.

B4X:
dim te (10)  ' Temperatur

for i = 1 to 10
  te(i) = 0
next i

' Temperatur messen
   for i = 1 to 10
      te(i) = temperatur () ' funktion die die messung durchführt.
   next i

te_all = 0
for i = 1 to 10
  te_all = te_all + te(i)
next i

richtigen_temperatur = te_all / 100

Gruß

Pucki
 

Wolli013

Well-Known Member
Licensed User
Longtime User
@pucki Danke für deine Mithilfe, aber irgenwie passen die Werte überaupt nicht.
Hier mein geänderter Code
B4X:
 Dim bc As ByteConverter
    For Each id As String In Characteristics.Keys   
        
        If id = "f000aa21-0451-4000-b000-000000000000" Then   
            Log("Temp Hex: "&bc.hexFromBytes(Characteristics.Get("f000aa21-0451-4000-b000-000000000000")))               
            Dim ArrayBytes() As Byte = Characteristics.Get("f000aa21-0451-4000-b000-000000000000")
            Dim temp As Float = bc.FloatsFromBytes(Array As Byte(ArrayBytes(0), ArrayBytes(1), ArrayBytes(2), ArrayBytes(3)))(0)
 
            Log($"TestVal: ${temp}"$)
            
    
    Dim h1,h2 As String   
    h1 = bc.hexFromBytes(Characteristics.Get("f000aa21-0451-4000-b000-000000000000")).SubString2(0, 4) 'Umwandeln in dez   
    h2 = bc.hexFromBytes(Characteristics.Get("f000aa21-0451-4000-b000-000000000000")).SubString2(4, 8) 'Umwandeln in dez     
 
 Log(h1)
 Log(h2)
 
 Dim di As Int
 di = Bit.ParseInt(h1, 16)
  Log ("DI0 = "& di)
 di = (di / 65536 * 165 ) - 40   
 Log ("DI1 = "& di)
 
  Dim di As Int
 di = Bit.ParseInt(h2, 16)
 di = (di / 65536 * 100)
 Log ("DI2 = "& di)
 
 
            
           Dim te1 As String = ArrayBytes(0)
           Log("te1 " & te1)
           Dim te2 As String = ArrayBytes(1)
           Log("te2 " & te2)
           Dim te3 As String = ArrayBytes(2)
           Log("te3 " & te3)
           Dim te4 As String = ArrayBytes(3)
           Log("te4 " & te4)
 
        End If
    Next

Hier das Log Ergebniss
2C5F
6040
DI0 = 11359
DI1 = -11
DI2 = 37
te1 44
te2 95
te3 96
te4 64
Temp Hex: 345F6040
TestVal: 2.0803509E-7
345F
6040
DI0 = 13407
DI1 = -6
DI2 = 37
te1 52
te2 95
te3 96
te4 64
Temp Hex: 385F6040
TestVal: 5.3256983E-5
385F
6040
DI0 = 14431
DI1 = -3
DI2 = 37
te1 56
te2 95
te3 96
te4 64
Temp Hex: 345F6040
TestVal: 2.0803509E-7
345F
6040
DI0 = 13407
DI1 = -6
DI2 = 37
te1 52
te2 95
te3 96
te4 64
Disconnected
** Activity (main) Pause, UserClosed = false **
 

Wolli013

Well-Known Member
Licensed User
Longtime User
So, habe es jetzt soweit hinbekommen!
Nur was sehr komisch ist, wenn ich den Ti-Sensor-Tag anhauche um die Luftfeuchtigkeit zu erhöhen, kommen auf einmal ab ca. 50% Luftfeuchte
Minuswerte und passen dann garnicht mehr, bis sich der Sensor normalisiert hat dann geht er wieder, vorrausgesetzt er bleibt unter 50%

Weis einer wo da der Fehler in meinem Code liegt?

B4X:
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")
 
        tem = ArrayBytes(0) + (ArrayBytes(1) * 256)
        hum = ArrayBytes(2) + (ArrayBytes(3) * 256)
 
        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))
 
End Sub
 
Last edited:

MaFu

Well-Known Member
Licensed User
Longtime User
Es liegt vermutlich daran dass es in Java keine "unsigned" Datentypen gibt. In einem Byte ist daher jeder Wert > 127 ein Minuswert.
Versuchs mal so:
B4X:
...
        tem = Bit.Or(Bit.ShiftLeft(ArrayBytes(1), 8), ArrayBytes(0))
        hum = Bit.Or(Bit.ShiftLeft(ArrayBytes(3), 8), ArrayBytes(2))
...
 

DonManfred

Expert
Licensed User
Longtime User

Wolli013

Well-Known Member
Licensed User
Longtime User
Leider geht das von MaFu und Erel nicht.
Hier mal ein Log auszug
Feuchte = 34
Temperatur-Grad = 23.34
Temperatur-Fahrenheit = 74
Feuchte = 33.72
Temperatur-Grad = 23.34
Temperatur-Fahrenheit = 74
Feuchte = -0.17
Temperatur-Grad = 23.34
Temperatur-Fahrenheit = 74
Feuchte = 33.23
Connected: CC2650 SensorTag
Temperatur-Grad = 23.34
Temperatur-Fahrenheit = 74
Feuchte = 32.94
Temperatur-Grad = 23.34
Temperatur-Fahrenheit = 74
Feuchte = -0.07
Temperatur-Grad = 23.32
Temperatur-Fahrenheit = 73.97
Feuchte = 32.56
Temperatur-Grad = 23.34
Temperatur-Fahrenheit = 74
Feuchte = -0.16
Connected: CC2650 SensorTag
Temperatur-Grad = 23.34
Temperatur-Fahrenheit = 74
Feuchte = 32.07
Temperatur-Grad = 23.34
Temperatur-Fahrenheit = 74
Feuchte = -0.15
Temperatur-Grad = 23.34
Temperatur-Fahrenheit = 74
Feuchte = 31.68
Temperatur-Grad = 23.32
Temperatur-Fahrenheit = 73.97
Feuchte = -0.05
Connected: CC2650 SensorTag
Temperatur-Grad = 23.32
Temperatur-Fahrenheit = 73.97
Feuchte = 31.4
Temperatur-Grad = 23.32
Temperatur-Fahrenheit = 73.97
Feuchte = -0.05

Und das kommt bei Erel sein Code raus
tem = (ArrayBytes(1)*256) + ArrayBytes(0)
tem = Bit.And(0xFF, tem)
hum = (ArrayBytes(3)*256) + ArrayBytes(2)
hum = Bit.And(0xFF, hum)

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
 
Last edited:

pucki

Active Member
Licensed User
Longtime User
Vielleicht suchen wir an der falschen Stelle nach den Fehler. Das Teil ist lt. Video mit den Studio-Teil ja programmierbar.
Wenn die Software in den Teil Mist ist, liefert sie auch nur Mist ab. Das logisch ist.

Ich würde mal versuchen das Teil mit der Studio-Software (liefert TI for free) zu testen.

Auch hab ich noch nicht raus gefunden ob das Teil eigene Sensoren hat, oder ob man Sensoren extra dabei kaufen muss. Wenn man da extra Sensoren kaufen muss, kann es sein das es ein Kalibrierungs-Problem ist.

Aber ich gebe zu das ich mich auch irren kann. So Teile kommen alle 5 Minuten auf den Markt. Und ich habe mich für die Arduino-Teile entschlossen. Da hänge ich dann "China-Sensoren" dran die ich lt. Datenblatt des Herstellers auslesen. Allerdings habe ich noch nie ein Bluetooth-Teil daran angeschlossen.

Gruß

Pucki
 
Last edited:

Wolli013

Well-Known Member
Licensed User
Longtime User
So wie es aussieht habe ich es durch Erel seiner Anregung hinbekommen!
Ich werde jetzt noch ein bisschen testen und wenn es dann wirklich läuft, poste ich nochmal den gesamten BLE Teil zum auslesen des TI Sensortag.
ich denke das wird für manch anderen auch sehr hilfreich sein!
 

pucki

Active Member
Licensed User
Longtime User
fein, freut mich. Und es kann immer helfen wenn man was mehr weiß. ;)

Ich lese bei mein Teilen für den Arduino hier auch viel nach.

Gruß

Pucki
 
Top