Android Question [Solved] Problem with BluetoothManager

Yayou49

Active Member
Licensed User
Hi,

With the code below (using BlueToothManager), I'm facing an issue with sending message.
Bt1 is used to create the connection with the bluetooth.
When the connection is up, "Sub AfterConnect" is raised and send a message with
B4X:
Starter.Manager.SendMessage(Message)

In my case, message is not received by the bluetooth.

I've added a new button with the same code.
So, if I click on button 1 and after on button 2, in that case, it works. Message is well received.

So, my question is: Why the send message in sub AfterConnect doesn't work ?
(even with a sleep before the send doesn't change my problem)

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("init")
    Message = "Hello"
End Sub

public Sub connection
    Dim device As NameAndMac
    device.Name = "HC-05"
    device.Mac = "AA:BB:CC:DD:EE:FF"
    Starter.Manager.ConnectTo(device)
 End Sub

Public Sub AfterConnect (Success As Boolean)
    ProgressDialogHide

    If Success = True Then
             Starter.Manager.SendMessage("Hello")
    End If
End Sub

Sub Bt1_Click
    connection
End Sub

Sub Bt2_Click
    Starter.Manager.SendMessage("Hello")
End Sub

Thanks in advance for your help.
And Merry Christmas to all of you
 

Yayou49

Active Member
Licensed User
Solution found....
In fact, in the sub "Serial_Connected" of BlueToothManager, Callsub2(... ,AfterConnect,...) is called before the Astream.Initialize is done.
So I just moved the callsub2 from the begining to the end of "Serial_Connected".

Works perfectly.

Thanks for help !!!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…