Android Question Bluetooth pairing

scarr

Member
Licensed User
Longtime User
Hi All,

OK, I have a HC-05 module, when I search for the HC-05 using the phones built in bluetooth pairing it see it and I can pair with it, I can also see another nearby mobile phone however when I run my app and search for the HC-05 it fails to see it or the other phone! If I have already paired with the HC-05 I can select it from the paired list in my app and it works fine!

I do not move phone or HC-05 during either test. Any ideas anyone?

B4X:
Sub btnSearchForDevices_Click
    Dim PairedDevices As Map
    PairedDevices = serial1.GetPairedDevices
    Dim l As List
    l.Initialize
    For i = 0 To PairedDevices.Size - 1
        l.Add(PairedDevices.GetKeyAt(i))
    Next
    If l.Size > 0 Then
        Dim res As Int
        res = InputList(l, "Choose device", -1) 'show list with paired devices
        If res <> DialogResponse.CANCEL Then
              serial1.Connect(PairedDevices.Get(l.Get(res))) 'convert the name to mac address and connect
        Else
            foundDevices.Initialize
            If Admin.StartDiscovery    = False Then
                ToastMessageShow("Error starting discovery process.", True)
            Else
                ProgressDialogShow("Searching for devices...")
            End If
        End If
    Else
        foundDevices.Initialize
        If Admin.StartDiscovery    = False Then
            ToastMessageShow("Error starting discovery process.", True)
        Else
            ProgressDialogShow("Searching for devices...")
        End If
    End If
End Sub
 
Last edited:

scarr

Member
Licensed User
Longtime User
Hmmm, am I asking a stupid question or is this something that nobody has any ideas how to solve?

Steve
 
Upvote 0

GMan

Well-Known Member
Licensed User
Longtime User
I am using also HC-05's and HC-06's - but am not at home in the moment to look @ my code.
Tomorrow i can send you my code part which works perfectly.

P.S.: there are mostly no stupid questions, only stupid answers :)
 
Upvote 0

scarr

Member
Licensed User
Longtime User
I am using also HC-05's and HC-06's - but am not at home in the moment to look @ my code.
Tomorrow i can send you my code part which works perfectly.

P.S.: there are mostly no stupid questions, only stupid answers :)

Thanks GMan, that would help a lot.
 
Upvote 0

scarr

Member
Licensed User
Longtime User
Been playing whilst I wait for Gman's reply and I am beginning to think it's the phone (S5), I have another cheap phone and using this phone I test the Bluetooth example from here:-

https://www.b4x.com/android/forum/threads/android-bluetooth-bluetoothadmin-tutorial.14768/

it see's the HC-05, but the same example on my S5 fails to see it!!!

What could possibly cause this, keeping in mind that on the S5 when I go to the phones "Bluetooth search" I can see the HC-05 and even pair with it!

Thanks

Steve
 
Upvote 0

scarr

Member
Licensed User
Longtime User
Which version of the Serial library are you using? If it is lower than 1.26 then try to add this line to the manifest editor:
B4X:
AddPermission("android.permission.ACCESS_COARSE_LOCATION")

Erel you are the man :) now working fine, thanks
 
Upvote 0

wigigo

Member
Licensed User
Longtime User
I'm using serial 1.26. I add the permission access_coarse_location. i'm running b4a 6.5
the discovery process fires the start and finished event, but never the devicefound event

the serial getpaireddevices show all possible devices, but serial.connect dosn't connect to the choosen device.

manually i can choose the device, it's working fine.
 
Upvote 0
Top