Good Day all,
For the past two years I have been using an app to control water levels with no issues. Yesterday I upgraded my android device to a Samsung note. I can send data to my Arduino H6, however when I receive data back the app locks.
Thanks All
The following is my code:
For the past two years I have been using an app to control water levels with no issues. Yesterday I upgraded my android device to a Samsung note. I can send data to my Arduino H6, however when I receive data back the app locks.
Thanks All
The following is my code:
B4X:
#Region Module Attributes
#FullScreen: False
#IncludeTitle: True
#ApplicationLabel: greenHAUS
#VersionCode: 1
#VersionName: 1
#SupportedOrientations: portrait
#End Region
'Activity module
Sub Process_Globals
Dim Serial1 As Serial
Dim TextReader1 As TextReader
Dim TextWriter1 As TextWriter
Dim Timer1 As Timer
Dim connected As Boolean
End Sub
Sub Globals
Dim btnSend As Button
Dim txtLog As EditText
Dim txtSend As EditText
Private Button1 As Button
Private btnDisconnect As Button
Private Button1a As Button
Private btnClose10 As Button
Private btnComs As Button
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
Serial1.Initialize("Serial1")
Timer1.Initialize("Timer1", 100)
End If
Activity.LoadLayout("gardenStart")
End Sub
Sub Activity_Resume
If Serial1.IsEnabled = False Then
Msgbox("Please enable Bluetooth.", "")
Else
Serial1.Listen 'listen for incoming connections
End If
End Sub
Sub mnuConnect_Click
Dim PairedDevices As Map
PairedDevices = Serial1.GetPairedDevices
Dim l As List
l.Initialize
For i = 0 To PairedDevices.Size - 1
l.Add(PairedDevices.GetKeyAt(i))
Next
Dim res As Int
res = InputList(l, "Choose device", -1) 'show list with paired devices
If res <> DialogResponse.CANCEL Then
Serial1.Connect(PairedDevices.Get(l.Get(res))) 'convert the name to mac address
End If
End Sub
Sub Serial1_Connected (Success As Boolean)
If Success Then
ToastMessageShow("Connected successfully", False)
TextReader1.Initialize(Serial1.InputStream)
TextWriter1.Initialize(Serial1.OutputStream)
Timer1.Enabled = True
connected = True
Activity.RemoveAllViews
Activity.LoadLayout("gardenPage1")
Else
connected = False
Timer1.Enabled = False
Msgbox(LastException.Message, "Error connecting.")
End If
End Sub
Sub mnuDisconnect_Click
Serial1.Disconnect
connected = False
End Sub
Sub Activity_Pause (UserClosed As Boolean)
Serial1.Disconnect
connected = False
Activity.RemoveAllViews
Activity.LoadLayout("gardenStart")
End Sub
Sub btnSend_Click
If connected Then
TextWriter1.WriteLine(txtSend.Text)
TextWriter1.Flush
txtSend.Text = ""
End If
End Sub
Sub Timer1_Tick
'error here <-------------------------------------------------
If connected Then
If TextReader1.Ready Then 'check if there is any data waiting to be read
txtLog.Text = txtLog.Text & TextReader1.ReadLine & CRLF
txtLog.SelectionStart = txtLog.Text.Length
End If
End If
'error here <-------------------------------------------------
End Sub
Sub Button1_Click
Dim PairedDevices As Map
PairedDevices = Serial1.GetPairedDevices
Dim l As List
l.Initialize
For i = 0 To PairedDevices.Size - 1
l.Add(PairedDevices.GetKeyAt(i))
Next
Dim res As Int
res = InputList(l, "Choose device", -1) 'show list with paired devices
If res <> DialogResponse.CANCEL Then
Serial1.Connect(PairedDevices.Get(l.Get(res))) 'convert the name to mac address
End If
End Sub
Sub btnDisconnect_Click
Serial1.Disconnect
connected = False
Activity.RemoveAllViews
Activity.LoadLayout("gardenStart")
End Sub
Sub Button1a_Click
If connected Then
TextWriter1.Write(1)
TextWriter1.Flush
txtSend.Text = ""
End If
End Sub
Sub btnClose10_Click
Activity.RemoveAllViews
Activity.LoadLayout("gardenPage1")
End Sub
Sub btnComs_Click
Activity.RemoveAllViews
Activity.LoadLayout("gardenPage10")
End Sub