Hello everyone I'm new here, I have a school project to do with B4A and I have a problem with it. I hope I post this in the right place and I will try to explain as clearly as I can but it'll probably be long.
Basically, I have an arduino that simulates a bike moving, it's giving me a line every 5 seconds with the latitude and longitude of the bike :
So I made an application on my phone that reads the data and show them to the log :
As you can see, my problem is that sometimes the lines randomly split into 2 lines and I don't know why. In the picture, after the first line, 5 seconds later I get 2 lines but it's supposed to be just 1. The 5th line is split too but this time only with one character.
I considered that it was ok because I only need the numbers in the line so I did this code to get all 4 numbers :
It gives me this :
My latitude is lati = coordonnes(0) & " " & coordonnes(1) and my longitude is longi = coordonnes(2) & " " & coordonnes(3) .
So as you can see it works but on the 3rd line of log (so 2nd transmission of arduino), "4338 20628" are coordonnes(0) and coordonnes(1) but on the next line "00509 17113" are coordonnes(0) and coordonnes(1) as well because it's another line from the log as I showed before so Lati get erased by Longi in a way. How can I conter this problem ? I would like to have "4338 20628 00509 17113" on only 1 line of the log. I tried multiple things and none of them were concluant. I hope someone can help me and I will explain differently if you did'nt understand !
Basically, I have an arduino that simulates a bike moving, it's giving me a line every 5 seconds with the latitude and longitude of the bike :
So I made an application on my phone that reads the data and show them to the log :
As you can see, my problem is that sometimes the lines randomly split into 2 lines and I don't know why. In the picture, after the first line, 5 seconds later I get 2 lines but it's supposed to be just 1. The 5th line is split too but this time only with one character.
I considered that it was ok because I only need the numbers in the line so I did this code to get all 4 numbers :
Get the numbers:
Private Sub serial_DataAvailable (Buffer() As Byte)
Dim data As String
data = bc.StringFromBytes(Buffer,"ASCII")
Dim coordonnees(4) As String
Dim m As Matcher = Regex.Matcher("\d+", data)
For i = 0 To 3
If m.Find Then
coordonnees(i) = m.Match
End If
Next
Log(coordonnees(0) & " " & coordonnees(1) & " " & coordonnees(2) & " " & coordonnees(3))
End Sub
It gives me this :
My latitude is lati = coordonnes(0) & " " & coordonnes(1) and my longitude is longi = coordonnes(2) & " " & coordonnes(3) .
So as you can see it works but on the 3rd line of log (so 2nd transmission of arduino), "4338 20628" are coordonnes(0) and coordonnes(1) but on the next line "00509 17113" are coordonnes(0) and coordonnes(1) as well because it's another line from the log as I showed before so Lati get erased by Longi in a way. How can I conter this problem ? I would like to have "4338 20628 00509 17113" on only 1 line of the log. I tried multiple things and none of them were concluant. I hope someone can help me and I will explain differently if you did'nt understand !
Attachments
Last edited: