Android Question Bluetooth Example not working

jcohedman

Member
Licensed User
Longtime User
Happy New Year to all!

I'm using Arduino Mini 328, B.T. Shield V2.2 as slave and Acer Iconia Tablet.
When sending timed strings from Arduino, suddenly "Bluetooth Example" stops receiving data. I can send from it to Arduino, it continues receiving...
AStreams_Error don't report any problem.
I'have tested with two different systems, and it repeats the fail.
Anybody has a clue?
 

jcohedman

Member
Licensed User
Longtime User
How are you initializing AsyncStreams? Make sure to use non-prefix mode as your Arduino device doesn't implement this protocol.
If AStreams.IsInitialized = False Then
'AStreams.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStreams")
AStreams.Initialize(Main.serial1.InputStream, Main.serial1.OutputStream, "AStreams")
End If
 
Upvote 0

jcohedman

Member
Licensed User
Longtime User
[/ATTACH] this is the screen of Bluetooth Example in B4A that appears when the system stop working. I verified that Arduino continues sending data, the bluetooth device is working.

this is the code:
----------------------------------------------------------------------------------------------------------------------
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("2")
If AStreams.IsInitialized = False Then
'AStreams.InitializePrefix(Main.serial1.InputStream, True, Main.serial1.OutputStream, "AStreams")
AStreams.Initialize(Main.serial1.InputStream, Main.serial1.OutputStream, "AStreams")
End If
txtLog.Width = 100%x

If File.Exists(File.DirRootExternal, "errores.txt") Then
Dim TextReader1 As TextReader
Dim sb As StringBuilder
TextReader1.Initialize(File.OpenInput(File.DirRootExternal, "errores.txt"))
TextReader1.Close

Else
Dim TextWriter1 As TextWriter
TextWriter1.Initialize(File.OpenOutput(File.DirRootExternal, "errores.txt", False))
TextWriter1.Close
End If
End Sub

Sub guardar_error
Dim TextWriter1 As TextWriter
TextWriter1.Initialize(File.OpenOutput(File.DirRootExternal, "errores.txt", False))
TextWriter1.WriteLine(error)
TextWriter1.WriteLine(error2)
TextWriter1.WriteLine("lectura: ")
TextWriter1.WriteLine(lectura)
TextWriter1.Close

End Sub

Sub AStreams_NewData (Buffer() As Byte)
total=total+1
LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8")& " " & total)
lectura = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
End Sub

Sub AStreams_Error
ToastMessageShow("Connection is broken.", True)
btnSend.Enabled = False
txtInput.Enabled = False

error="Astreams Error"
error2=total
guardar_error


End Sub

Sub AStreams_Terminated
error="Astreams Terminated"
guardar_error
AStreams_Error
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)
If UserClosed Then

error="UserClosed"
guardar_error


AStreams.Close
End If
End Sub

Sub txtInput_EnterPressed
If btnSend.Enabled = True Then btnSend_Click
End Sub
Sub btnSend_Click
AStreams.Write(txtInput.Text.GetBytes("UTF8"))
txtInput.SelectAll
txtInput.RequestFocus
LogMessage("Me", txtInput.Text)
End Sub

Sub LogMessage(From As String, Msg As String)
txtLog.Text = txtLog.Text & From & ": " & Msg & CRLF
txtLog.SelectionStart = txtLog.Text.Length
End Sub
----------------------------------------------------------------------------------------------------------------------

what can I do?
 

Attachments

  • b4a_bluetooth.jpg
    b4a_bluetooth.jpg
    129.3 KB · Views: 168
  • b4a_main_B.T.FALLADO.jpg
    b4a_main_B.T.FALLADO.jpg
    17.9 KB · Views: 126
Upvote 0

jcohedman

Member
Licensed User
Longtime User
sorry for my ignorance, but if arduino is sending data as text, why am I considering it as Byte?

Sub AStreams_NewData (Buffer() As Byte)
total=total+1
LogMessage("You", BytesToString(Buffer, 0, Buffer.Length, "UTF8")& " " & total)
lectura = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
End Sub
 
Upvote 0
Top