'MAC address Ruuivi sensor
Private BLE_MAC_ADDRESS As String = "NN:NN:NN:NN:NN:NN"
'UUIDs (lowercase)
'UUID remote service to connect (UART_SERVICE_UUID)
Private SERVICE_UUID As String = "6e400001-b5a3-f393-e0a9-e50e24dcca9e"
'UUID for characteristic of the remote service holding the advertised data (UART_TX_CHAR_UUID).
Private CHAR_UUID As String = "6e400003-b5a3-f393-e0a9-e50e24dcca9e"
Sub BLEManager_DataAvailable
# vom Bluetooth-Client empfangene Daten, angefordert von start_notify()
def handle_rx(sender_handle: int, data: bytearray):
Dim b() As Byte = Characteristics.Get(BLECharId)
if b(0) == 0x05 'DATATYPE_ADV
if b.Length != 18 then error und return ' print("Header = advertisement data, but wrong size", flush=True)
Log('Advertisement data received. Converting...')
dim b1 as int = b(1)
dim t as double = b1 / 200.0 '°C
dim b2 as int = b(2)
dim h as double = b2 / 400.0 '%RH
dim b3 as int = b(3)
dim p as double = b3 + 50000/ 100.0 'mBar
Connected: [00001800-0000-1000-8000-00805f9b34fb, 00001801-0000-1000-8000-00805f9b34fb, 0000180a-0000-1000-8000-00805f9b34fb, 6e400001-b5a3-f393-e0a9-e50e24dcca9e]
Ich habe die protokoll information gelesen und in ein testsub mit den daten (050E...) umgesetzt für dataformat 05.Und das sind die Ergebnisse
BLEManager_DataAvailable: service=6e400001-b5a3-f393-e0a9-e50e24dcca9e, characteristics={6e400003-b5a3-f393-e0a9-e50e24dcca9e=[B@6b95b45}
050E8A6B66C097FFC003E80018A8D66FCBB1
Advertisement data received Converting
0.07
-0.295
607
Private Sub BLEManager_DataAvailable (SrvId As String, Characteristics As Map)
Log($"BLEManager_DataAvailable: service=${SrvId}, characteristics=${Characteristics}"$)
ConvertPayload(bc.HexFromBytes(Characteristics.Get(BLECharId)))
End Sub
'Testdata:
'ConvertPayload("05 0E 8A 6B 66 C0 97 FF C0 03 E8 00 18 A8 D6 6F CB B1")
'Example Output:
'050E8A6B66C097FFC003E80018A8D66FCBB1
'data format: 5
'hex=0E8A, t=19 °C
'hex=6B66, h=69 %RH
'hex=C097, p=99,303 Pa
Sub ConvertPayload(payload As String)
Dim bc As ByteConverter
payload = payload.Replace(" ", "")
Dim b() As Byte = bc.HexToBytes(payload)
Dim hex As String
'Check the data format = Byte 0 = value must be 5 (dataformat_05)
Dim hex As String = payload.SubString2(1,2)
Log($"data format: ${hex}"$)
hex = payload.SubString2(2, 6)
' Temperature Degree C = Bytes 1 and 2
Dim temperature As Double = Bit.ParseInt(hex, 16) * 0.005
Log($"hex=${hex}, t=${NumberFormat(temperature,0,0)} °C"$)
' Humidity %RH = Bytes 3 and 4
hex = payload.SubString2(6, 10)
Dim humidity As Double = Bit.ParseInt(hex, 16) * 0.0025
Log($"hex=${hex}, h=${NumberFormat(humidity,0,0)} %RH"$)
' Pressure Pa - Bytes 5 and 6
hex = payload.SubString2(10, 14)
Dim pressure As Double = Bit.ParseInt(hex, 16) + 50000
Log($"hex=${hex}, p=${NumberFormat(pressure,0,1)} Pa"$)
' Log($"t=${temperature}, h=${humidity}, p=${pressure}"$)
[CODE=b4x]
Private BLEServiceId, BLERXCharId, BLETXCharId As String
Private RX_CHAR_UUID As String = "6e400002-b5a3-f393-e0a9-e50e24dcca9e"
Private TX_CHAR_UUID As String = "6e400003-b5a3-f393-e0a9-e50e24dcca9e"
BLEServiceId = SERVICE_UUID
BLERXCharId = RX_CHAR_UUID
BLETXCharId = TX_CHAR_UUID
BLEManager.SetNotify(BLEServiceId, BLERXCharId, True)
BLEManager.SetNotify(BLEServiceId, BLETXCharId, True)
BLEManager_DataAvailable (SrvId As String, Characteristics As Map)
Log($"BLEManager_DataAvailable: service=${SrvId}, characteristics=${Characteristics}"$)
'Advertisement data received
If (Characteristics.ContainsKey(BLETXCharId)) Then
Dim b() As Byte = Characteristics.Get(BLETXCharId)
...
End If
'Log data
If (Characteristics.ContainsKey(BLERXCharId)) Then
Dim b() As Byte = Characteristics.Get(BLERXCharId)
...
End If
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?