Android Question Sensorion SmartGadget

Brandsum

Well-Known Member
Licensed User
The info you have provided is not gonna help you much. Its impossible to guess that does those subs are for without reading the documentation. You should post your code or project along with much information that will help other members to understand.
 

Wolli013

Active Member
Licensed User
That's my code right now.
I just don't know how to get directly to the temperature and humidity data.

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
End Sub

Sub Service_Start (StartingIntent As Intent)
End Sub

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

Public Sub Scan
    If manager.State <> manager.STATE_POWERED_ON Then
        Log("Not powered on")
    Else
        manager.Scan(Null) 'alle Geräte scannen
    End If
End Sub
 
Public Sub ReadData
    For Each s As String In ConnectedServices
     manager.ReadData(s)
    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
End Sub


Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
 
If Id = "E6:8F:D7:A1:10:81" Then
    
    ConnectedName = Name
     manager.StopScan
      manager.Connect(Id)   
    
Log("SmartGadget1 Name: " & Name)
 Log("SmartGadget1 Mac Adresse: " & Id)
  Log("SmartGadget1 RSSI: " & RSSI)
   Log("SmartGadget Zusatzdaten: " & AdvertisingData)
 
End If
 

End Sub
 
Private Sub Manager_Connected (Services As List)
    Log("Connected")
    connected = True
    ConnectedServices = Services     
    
    For i=0 To Services.Size-1
        manager.ReadData(Services.Get(i))
    Next
End Sub

Private Sub Manager_DataAvailable (Srv As String, Characteristics As Map)
    
''DEVICE_SERVICE_UUID = "0000180a-0000-1000-8000-00805f9b34fb"
''MANUFACTURER_NAME_CHARACTERISTIC_UUID = '00002a29-0000-1000-8000-00805f9b34fb'
''MODEL_NUMBER_CHARACTERISTIC_UUID = '00002a24-0000-1000-8000-00805f9b34fb'
''SERIAL_NUMBER_CHARACTERISTIC_UUID = '00002a25-0000-1000-8000-00805f9b34fb'
''HARDWARE_REVISION_CHARACTERISTIC_UUID = '00002a27-0000-1000-8000-00805f9b34fb'
''FIRMWARE_REVISION_CHARACTERISTIC_UUID = '00002a26-0000-1000-8000-00805f9b34fb'
''SOFTWARE_REVISION_CHARACTERISTIC_UUID = '00002a28-0000-1000-8000-00805f9b34fb'
'
''BATTERY_SERVICE_UUID = '0000180f-0000-1000-8000-00805f9b34fb'
''BATTERY_LEVEL_CHARACTERISTIC_UUID = '00002a19-0000-1000-8000-00805f9b34fb'
'
''SHT3X_HUMIDITY_SERVICE_UUID = '00001234-b38d-4985-720e-0f993a68ee41'
''SHT3X_HUMIDITY_NOTIFICATIONS_UUID = '00001235-b38d-4985-720e-0f993a68ee41'
'
''SHT3X_TEMPERATURE_SERVICE_UUID = '00002234-b38d-4985-720e-0f993a68ee41'
''SHT3X_TEMPERATURE_NOTIFICATIONS_UUID = '00002235-b38d-4985-720e-0f993a68ee41'
'
''NOTIFICATION_DESCRIPTOR_UUID = '00002902-0000-1000-8000-00805f9b34fb'
''NOTIFICATION_ON = b'\x01'
''NOTIFICATION_OFF = b'\x00'   
    
    Log(Srv)
    
    Dim KeyCode As String
        Dim BC As ByteConverter   
 
    For i = 0 To Characteristics.Size - 1
        
        Log("Key: " & Characteristics.GetKeyAt(i))
        Log("Val: " & Characteristics.GetValueAt(i))
        Log("Str: " & BC.StringFromBytes(Characteristics.GetValueAt(i),"utf-8"))
        
           For Each id As String In Characteristics.Keys
             KeyCode = Characteristics.Get(id)
             Log("Hex: " & BC.HexFromBytes(Characteristics.Get(id)))         
           Next
 
        If Srv="0000180f-0000-1000-8000-00805f9b34fb" Then ' 180F=Battery Service , 2A19=Battery Level
           For Each id As String In Characteristics.Keys
             KeyCode = Characteristics.Get(id)
             Log("keyCode=" & KeyCode&" Hex: "&BC.HexFromBytes(Characteristics.Get(id)))           
           Next
        End If
 
    Next
    Log(" ")
End Sub

Sub Manager_Disconnected
    Log("Disconnected")
    connected = False
End Sub

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

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub
 

Brandsum

Well-Known Member
Licensed User
That's my code right now.
I just don't know how to get directly to the temperature and humidity data.

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
End Sub

Sub Service_Start (StartingIntent As Intent)
End Sub

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

Public Sub Scan
    If manager.State <> manager.STATE_POWERED_ON Then
        Log("Not powered on")
    Else
        manager.Scan(Null) 'alle Geräte scannen
    End If
End Sub
 
Public Sub ReadData
    For Each s As String In ConnectedServices
     manager.ReadData(s)
    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
End Sub


Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
 
If Id = "E6:8F:D7:A1:10:81" Then
   
    ConnectedName = Name
     manager.StopScan
      manager.Connect(Id)  
   
Log("SmartGadget1 Name: " & Name)
 Log("SmartGadget1 Mac Adresse: " & Id)
  Log("SmartGadget1 RSSI: " & RSSI)
   Log("SmartGadget Zusatzdaten: " & AdvertisingData)
 
End If
 

End Sub
 
Private Sub Manager_Connected (Services As List)
    Log("Connected")
    connected = True
    ConnectedServices = Services    
   
    For i=0 To Services.Size-1
        manager.ReadData(Services.Get(i))
    Next
End Sub

Private Sub Manager_DataAvailable (Srv As String, Characteristics As Map)
   
''DEVICE_SERVICE_UUID = "0000180a-0000-1000-8000-00805f9b34fb"
''MANUFACTURER_NAME_CHARACTERISTIC_UUID = '00002a29-0000-1000-8000-00805f9b34fb'
''MODEL_NUMBER_CHARACTERISTIC_UUID = '00002a24-0000-1000-8000-00805f9b34fb'
''SERIAL_NUMBER_CHARACTERISTIC_UUID = '00002a25-0000-1000-8000-00805f9b34fb'
''HARDWARE_REVISION_CHARACTERISTIC_UUID = '00002a27-0000-1000-8000-00805f9b34fb'
''FIRMWARE_REVISION_CHARACTERISTIC_UUID = '00002a26-0000-1000-8000-00805f9b34fb'
''SOFTWARE_REVISION_CHARACTERISTIC_UUID = '00002a28-0000-1000-8000-00805f9b34fb'
'
''BATTERY_SERVICE_UUID = '0000180f-0000-1000-8000-00805f9b34fb'
''BATTERY_LEVEL_CHARACTERISTIC_UUID = '00002a19-0000-1000-8000-00805f9b34fb'
'
''SHT3X_HUMIDITY_SERVICE_UUID = '00001234-b38d-4985-720e-0f993a68ee41'
''SHT3X_HUMIDITY_NOTIFICATIONS_UUID = '00001235-b38d-4985-720e-0f993a68ee41'
'
''SHT3X_TEMPERATURE_SERVICE_UUID = '00002234-b38d-4985-720e-0f993a68ee41'
''SHT3X_TEMPERATURE_NOTIFICATIONS_UUID = '00002235-b38d-4985-720e-0f993a68ee41'
'
''NOTIFICATION_DESCRIPTOR_UUID = '00002902-0000-1000-8000-00805f9b34fb'
''NOTIFICATION_ON = b'\x01'
''NOTIFICATION_OFF = b'\x00'  
   
    Log(Srv)
   
    Dim KeyCode As String
        Dim BC As ByteConverter  
 
    For i = 0 To Characteristics.Size - 1
       
        Log("Key: " & Characteristics.GetKeyAt(i))
        Log("Val: " & Characteristics.GetValueAt(i))
        Log("Str: " & BC.StringFromBytes(Characteristics.GetValueAt(i),"utf-8"))
       
           For Each id As String In Characteristics.Keys
             KeyCode = Characteristics.Get(id)
             Log("Hex: " & BC.HexFromBytes(Characteristics.Get(id)))        
           Next
 
        If Srv="0000180f-0000-1000-8000-00805f9b34fb" Then ' 180F=Battery Service , 2A19=Battery Level
           For Each id As String In Characteristics.Keys
             KeyCode = Characteristics.Get(id)
             Log("keyCode=" & KeyCode&" Hex: "&BC.HexFromBytes(Characteristics.Get(id)))          
           Next
        End If
 
    Next
    Log(" ")
End Sub

Sub Manager_Disconnected
    Log("Disconnected")
    connected = False
End Sub

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

Sub Application_Error (Error As Exception, StackTrace As String) As Boolean
    Return True
End Sub
So where did you called scan function?
 

Brandsum

Well-Known Member
Licensed User
Add a log(id) before

If Id = "E6:8F:D7:A1:10:81" Then

to check if that event is getting fired or not.
 
Top