Android Question howto get bluetooth LE scanresult

analizer3816

Member
Licensed User
Longtime User
I use Erel's blemanager library,on devicefound event can get devicename and macaddress.
howto get rssi from scanresult without connect (this has getRssi () : https://developer.android.com/reference/android/bluetooth/le/ScanResult.html)

**I try add this, it works for normal Bluetooth not Bluetooth LE**
**add to manifest**
AddReceiverText(BTService,
<intent-filter>
<action android:name="android.bluetooth.device.action.FOUND" />
</intent-filter>)

**and add to BTService**
Sub Service_Start (StartingIntent AsIntent)
If StartingIntent.Action = "android.bluetooth.device.action.FOUND"Then
Dim RSSI AsString = StartingIntent.GetExtra("android.bluetooth.device.extra.RSSI")
End If

End Sub

thanks
 

analizer3816

Member
Licensed User
Longtime User
I modified Erel's bleManager library and now I can read RSSI, scanRecord
Battery,temperature and Humidity level on BLE HM-10 and HM-11 without connect

:):)
 
Upvote 0

analizer3816

Member
Licensed User
Longtime User
**see example and use my library**
ble 4.0 Battery,temperature and Humidity level see page 23 in http://www.jnhuamao.cn/bluetooth40_en.zip
and use "AT+BATC1" command for enable battery monitor (one hour update once)

Sub BLE_DeviceFound (Name As String, MacAddress As String,rssi As Int, scanRecord() As Byte)
Dim i As Int
Dim sBatt As String = "0", sTemp As String = "0", sHumidity As String = "0"
For i = 0 To scanRecord.Length -1
If (i+7 < scanRecord.Length) Then
If (scanRecord(i) = 7 AND scanRecord(i+1) = 22 AND scanRecord(i+2) = 0AND scanRecord(i+3) = -80) Then
sBatt = scanRecord(i+7)
sHumidity = scanRecord(i+6)
sTemp = scanRecord(i+5)
EndIf
EndIf
Next
ListView1.AddTwoLines2(Name,rssi & " dBm: batt " & sBatt & " %: temp " & sTemp & " c: humi " & sHumidity & " %", MacAddress)

End Sub
 

Attachments

  • BLEManager_RSSI_Batt.zip
    366.4 KB · Views: 266
Upvote 0
Top