Android Question BLE2 not working

seskindell

Active Member
Licensed User
Longtime User
I can't get ANY example of BLE2 to work on my Samsung S5.
It shows BLE State "Powered ON" ... when I click SCAN it just keeps scanning finding no devices.
I have a few devices that every scanner in the playstore BLE apps finds .. but BLE2 doesn't find
anything. I have the latest B4A.

Please help.
 

seskindell

Active Member
Licensed User
Longtime User
Looking at the log it seems to find the devices however nothing is appearing in the list.

Logger connected to: 3b743dcb
--------- beginning of system
--------- beginning of main
** Activity (main) Pause, UserClosed = false **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Class not found: b4a.example.customlistview, trying: b4a.example3.customlistview
** Activity (main) Resume **
Found: , 1E:7D:D8:90:6D:1C, RSSI = -97, (MyMap) {-1=[B@3412a786, 0=[B@32a05847}
Found: , 6C:1C:72:41:B7:BB, RSSI = -76, (MyMap) {1=[B@37156874, 7=[B@37a9019d, 0=[B@de1b612}
Found: DfuTarg, D4:AC:14:8D:30:4C, RSSI = -64, (MyMap) {1=[B@128031e3, 2=[B@285a97e0, 9=[B@20191a99, 0=[B@3c21215e}
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.example3
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Class not found: b4a.example.customlistview, trying: b4a.example3.customlistview
** Activity (main) Resume **
Found: DfuTarg, D4:AC:14:8D:30:4C, RSSI = -48, (MyMap) {1=[B@37156874, 2=[B@37a9019d, 9=[B@de1b612, 0=[B@128031e3}
Found: OLP425-7539, 20:CD:39:7A:75:39, RSSI = -65, (MyMap) {1=[B@285a97e0, 10=[B@20191a99, 2=[B@3c21215e, 9=[B@1efa093f, 7=[B@501520c, 0=[B@9d7c755}
Disconnected
Disconnected
Found: DfuTarg, D4:AC:14:8D:30:4C, RSSI = -49, (MyMap) {1=[B@277782f8, 2=[B@3b9a83d1, 9=[B@3999fe36, 0=[B@5c9e137}
Found: OLP425-7539, 20:CD:39:7A:75:39, RSSI = -66, (MyMap) {1=[B@211dd6a4, 10=[B@17f28c0d, 2=[B@37ffc7c2, 9=[B@8d159d3, 7=[B@16b3b910, 0=[B@1f48dc09}
Disconnected
Disconnected
Found: OLP425-7539, 20:CD:39:7A:75:39, RSSI = -71, (MyMap) {1=[B@3783563c, 10=[B@159a2fc5, 2=[B@24928d1a, 9=[B@3580304b, 7=[B@3b4d9a28, 0=[B@7f30341}
Found: , 1E:7D:D8:90:6D:1C, RSSI = -100, (MyMap) {-1=[B@32bc60e6, 0=[B@179f8627}
Disconnected
Disconnected
** Activity (main) Pause, UserClosed = false **
PackageAdded: package:b4a.example3
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Class not found: b4a.example.customlistview, trying: b4a.example3.customlistview
** Activity (main) Resume **
Found: DfuTarg, D4:AC:14:8D:30:4C, RSSI = -49, (MyMap) {1=[B@37156874, 2=[B@37a9019d, 9=[B@de1b612, 0=[B@128031e3}
Disconnected
Found: DfuTarg, D4:AC:14:8D:30:4C, RSSI = -49, (MyMap) {1=[B@3c21215e, 2=[B@1efa093f, 9=[B@501520c, 0=[B@9d7c755}
Disconnected
 
Upvote 0

seskindell

Active Member
Licensed User
Longtime User
It is not an error. Ignore it. It happens because the custom view added with the designer was added with a different package name.

Based on the logs it did find several BLE devices.
Why does it not populate the listview?
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
The BLE example tries to connect to the first peripheral found. Based on the logs it fails to connect. Modify this code and make it connect to the correct one based on the Name:
B4X:
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
   Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData)
   ConnectedName = Name
   manager.StopScan
   manager.Connect2(Id, False) 'disabling auto connect can make the connection quicker
End Sub
 
Upvote 0

seskindell

Active Member
Licensed User
Longtime User
The BLE example tries to connect to the first peripheral found. Based on the logs it fails to connect. Modify this code and make it connect to the correct one based on the Name:
B4X:
Sub Manager_DeviceFound (Name As String, Id As String, AdvertisingData As Map, RSSI As Double)
   Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData)
   ConnectedName = Name
   manager.StopScan
   manager.Connect2(Id, False) 'disabling auto connect can make the connection quicker
End Sub
Here is my code:
B4X:
ConnectedName = Name
    If ConnectedName="OLP425-7539" Then
    Log("Found: " & Name & ", " & Id & ", RSSI = " & RSSI & ", " & AdvertisingData)
    manager.StopScan
    manager.Connect2(Id, False) 'disabling auto connect can make the connection quicker
    End If

I can not get this to connect to ANY device .. let alone the "OLP425-7539"

Everytime I press the "Scan & Connect" button it shows a disconnect .. it will never connect:

PackageAdded: package:b4a.example3
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
Class not found: b4a.example.customlistview, trying: b4a.example3.customlistview
** Activity (main) Resume **
Found: OLP425-7539, 20:CD:39:7A:75:39, RSSI = -70, (MyMap) {1=[B@bde7634, 10=[B@35f45c5d, 2=[B@3a1dd9d2, 9=[B@217feaa3, 7=[B@1a06c1a0, 0=[B@59f6159}
Disconnected
Found: OLP425-7539, 20:CD:39:7A:75:39, RSSI = -72, (MyMap) {1=[B@23fed12a, 10=[B@27b60b1b, 2=[B@11c724b8, 9=[B@1d4ae291, 7=[B@1710d5f6, 0=[B@25a03df7}
Disconnected
Found: OLP425-7539, 20:CD:39:7A:75:39, RSSI = -66, (MyMap) {1=[B@306c5b82, 10=[B@2a90c293, 2=[B@b9dd2d0, 9=[B@254e52c9, 7=[B@1008adce, 0=[B@33faf4ef}
Disconnected
Found: OLP425-7539, 20:CD:39:7A:75:39, RSSI = -73, (MyMap) {1=[B@c05d8da, 10=[B@392bf10b, 2=[B@34a92be8, 9=[B@14d89201, 7=[B@a78a8a6, 0=[B@f2692e7}
Disconnected
 
Upvote 0

seskindell

Active Member
Licensed User
Longtime User
Ok .. I found the reason .. if I run the app connected in release mode it will not connect to anything .. but will connect if
I am not physically connected to the pc.
 
Upvote 0
Top