Hi,
Trying to test a HC-05 with a nano, I'm facing an issue.
I have a code working very well as follow:
(code linked with BluetoothManager)
Now, my problem is to release the connection to HC-05 when event is done.
Target is to allow multiple devices to access the same HC-05.
So I've change my code to start the connection on push button and release the connection after sending message:
With this code, message is not received by HC-05 and app crash.
What do I miss ?
Thanks in advance for your help.
Trying to test a HC-05 with a nano, I'm facing an issue.
I have a code working very well as follow:
(code linked with BluetoothManager)
B4X:
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("init")
connection
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
Starter.Manager.Disconnect
End If
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)
ProgressDialogShow2($"Trying to connect to: ${device.Name} (${device.Mac})"$, False)
End Sub
Public Sub AfterConnect (Success As Boolean)
ProgressDialogHide
End Sub
Sub Bt1On_Click
Starter.Manager.SendMessage("Hello")
End Sub
Now, my problem is to release the connection to HC-05 when event is done.
Target is to allow multiple devices to access the same HC-05.
So I've change my code to start the connection on push button and release the connection after sending message:
B4X:
Sub Globals
Dim Message As String
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("init")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then
Starter.Manager.Disconnect
End If
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)
ProgressDialogShow2($"Trying to connect to: ${device.Name} (${device.Mac})"$, False)
End Sub
Public Sub AfterConnect (Success As Boolean)
ProgressDialogHide
If Success = True Then
Send
End If
End Sub
Sub Send
Starter.Manager.SendMessage(Message)
Starter.Manager.Disconnect
End Sub
Sub Bt1On_Click
connection
Message = "Hello"
End Sub
With this code, message is not received by HC-05 and app crash.
What do I miss ?
Thanks in advance for your help.