This code is in a starter module. I connect and see the ESP32 message and the list. On timer tick I extract the variables and use for other activities through refresh subroutines. Every time I use NewList.get() my program crashes. If I just assign strings to the variable then works fine...
Am I doing something wrong with the list call?
Am I doing something wrong with the list call?
B4X:
#Region Service Attributes
#StartAtBoot: False
#ExcludeFromLibrary: True
#End Region
Sub Process_Globals
Public ESP32Msg As String
'network stuff
Public astream As AsyncStreams
Public client As Socket
Public server As ServerSocket
Public const PORT As Int = 51042
Public IPAddr As String = "192.168.1.2"
Public Connected As Boolean
Public Max1 As String
Public Max2 As Int
Public Max3 As Int
Public Max4 As Int
Public Min1 As Int
Public Min2 As Int
Public Min3 As Int
Public Min4 As Int
Public Max5 As Int
Dim numbers() As String
Dim NewList As List
End Sub
Sub Service_Create
Dim RefreshTimer As Timer
RefreshTimer.Initialize("Timer1",20)
RefreshTimer.Enabled=True
ConnectToServer(IPAddr)
End Sub
'connects to the server.
Private Sub ConnectToServer(Host As String)
CloseExistingConnection
Dim client As Socket
client.Initialize("client")
client.Connect(Host, PORT, 10000)
Wait For Client_Connected (Successful As Boolean)
If Successful Then
astream.Initialize(client.InputStream,client.OutputStream, "astream")
Connected=True
CallSub2(Main,"StatusUpdate",Connected)
Else
Connected=False
CallSub2(Main,"StatusUpdate",Connected)
End If
End Sub
' Text Recieved, converted to string and displayed
Sub AStream_NewData (Buffer() As Byte)
ESP32Msg=BytesToString(Buffer,0,Buffer.Length,"UTF8") 'write buffer as string
ToastMessageShow(ESP32Msg,False)
numbers = Regex.Split(",",ESP32Msg)
NewList.Initialize2(numbers)
ToastMessageShow(NewList,False)
End Sub
'closes a connection
Sub CloseExistingConnection
If astream.IsInitialized Then astream.Close
If client.IsInitialized Then client.Close
End Sub
Sub AStream_Error
End Sub
Sub AStream_Terminated
End Sub
Sub Timer1_Tick
ExtractVariables
CallSub(PlayText,"PlayText_Refresh")
End Sub
'---------
Sub ExtractVariables
Max1="54"
Max1=NewList.get(1) ''
'Min1=NewList.get(2) ''
'Max2=NewList.get(3) ''
'Min2=NewList.get(4)
'Max3=NewList.get(5)
'Min3=NewList.get(6)
'Max4=NewList.get(7)
'Min4=NewList.get(8)
End Sub