Android Question Help with Bluetooth classic and Android

Beja

Expert
Licensed User
Longtime User
Hello all,
Trying to run the following code but I got the following error logs:


Code Listing:
Sub Process_Globals
    Private Serial1 As Serial
    Private AStream As AsyncStreams
End Sub

Sub Globals
    Private btnConnect As Button
    Private btnShoot As Button
    Private btnReset As Button
    Private lblStatus As Label
    Private ConnectedDevice As BluetoothConnection
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("main")
    If FirstTime Then
        Serial1.Initialize("Serial1")
    End If
End Sub

Sub Activity_Resume
    If Serial1.IsEnabled = False Then
        ToastMessageShow("Please enable Bluetooth.", True)
        Serial1.Enable
    Else
        Serial1.DiscoverDevices
    End If
End Sub

Sub Serial1_DeviceFound (Name As String, MacAddress As String)
    Log($"Found: ${Name} (${MacAddress})"$)
    If Name.ToLowerCase.Contains("hc") Then
        Serial1.Connect(MacAddress) ' Connect to HC-05 or HC-06
    End If
End Sub

Sub Serial1_Connected (Success As Boolean)
    If Success Then
        ToastMessageShow("Connected!", False)
        lblStatus.Text = "Connected"
        AStream.Initialize(Serial1.InputStream, Serial1.OutputStream, "AStream")
    Else
        lblStatus.Text = "Connection Failed"
    End If
End Sub

Sub btnShoot_Click
    If AStream.IsInitialized Then
        AStream.Write("S".GetBytes("UTF8"))
    End If
End Sub

Sub btnReset_Click
    If AStream.IsInitialized Then
        AStream.Write("R".GetBytes("UTF8"))
    End If
End Sub

Logs:

Main - 26: Unknown member: discoverdevices
Main - 24: Unknown member: enable
Main - 11: Unknown type: bluetoothconnection<br />Are you missing a library reference?

Any meaning appreciated
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
 
Upvote 1

f0raster0

Well-Known Member
Licensed User
Longtime User
...My project is to connect a mobile phone to Arduino board through bluetooth classic (HC-05 or o6)
Any pointing or direction appreciated.
 
Upvote 0
Top