Android Question Trying to connect to HC-05 BT module

Discussion in 'Android Questions' started by andyp, Apr 8, 2019.

  1. andyp

    andyp Member Licensed User

    Hi. Trying to connect to HC-05 BT module. To get me started, I am using this example https://www.b4x.com/android/forum/threads/hc-05-classic-bluetooth.66677/#content (just the android code) to try and achieve a connection to a HC-05 BT module.

    The BT module is connected to an Arduino + GPS module - the Arduino is sending Lat + Long over BT using the HC-05. I can use an app from the Play Store (Bluetooth Terminal HC-05) to see the serial data - so I know the Arduino / GPS / HC-05 is working.

    Using this example, I needed to change the target SDK in the manifest to 26, otherwise I have made no changes to the example code.

    I would think this should let me achieve a connection?

    There is no log error - simply trying to connect times out.....

    Any ideas? Thank you!
     
  2. andyp

    andyp Member Licensed User

    Ok, solved that - for anyone else:
    Needed to add runtime permissions for course location because SDK is > 19
     
    MarkusR likes this.
  3. emexes

    emexes Well-Known Member Licensed User

    Is there any log at all? Especially from:
    Code:
    Private Sub admin_DeviceFound (Name As String, MacAddress As String)
        
    Log($"Device found: ${Name}"$)
    If not, then add these Log lines and give it another go:
    Code:
    Sub Service_Create
        
    serial.Initialize("serial")
        admin.Initialize(
    "admin")
        
    Log("Initialize done")    '<== add this line
    End Sub

    Public Sub Connect
        admin.StartDiscovery
        
    Log("StartDiscovery done")    '<== add this line
        connecting = True
        
    CallSub(Main, "SetState")
    End Sub
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    I've updated the example:
    targetSdkVersion set to 26 and the coarse location permission is requested at runtime.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice