Android Question Parsing few strings

Pepebis

Member
Licensed User
Dear All , thank you for the previous response.
Although I'm having another problem here.
As I'm sending strings from sensors in format ( example: 22.4, 33.6 ) and parsing that to each value and next sending it into gauges and that is working just fine.
I'm also using a slider to set proper values on my external device ( this is also working ).
The problem is when I want to send another string to confirm value of slider on the external device and on the app.
I can't put all of this data in one string ( form device-side because I'm only some time changing this value, from another side reading data from sensors is being done every second ). So my idea was to create another string something like this: VAL.33 ( position of the slider on an external device ) which I will be sending just when I have change value.
And this is creating a problem with the previous parsing. So to sum up. I want to send two different strings and make two different parsings at the same time.
Best Regards ,
Semek
 

kisoft

Well-Known Member
Licensed User
Hi
In the previous thread I showed you how to send more than two thongs, use this method. With the regex method you can share very large strings.
 
Upvote 0

Pepebis

Member
Licensed User
Yes , but that was one string.
If i will send string which is starting from character let's say VAL . App is down .

Dim str As String 'Received string
str = BytesToString(Packet.Data,Packet.Offset,Packet.Length, "UTF8" )

Dim Pos As Int = str.IndexOf(",")
Dim Temp As Double = str.SubString2(0,Pos)
Dim Humid As Double = str.SubString(Pos + 1)

Log(Temp)
Log(Humid)

So im getting bytes , then removing headers and taking just data and it's fine . But if i want to send different string .... this will not work .
Regrds , Semek
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
maybe you should show what you have and what you want. It's not clear right now.
 
Upvote 0

Pepebis

Member
Licensed User
I'm connected with RPI which is being connected with plc.
Plc is sending data to Rpi and Rpi is connected with the app .
App is reading values from sensors every each second ( pressure, temp, etc... ) . " Man in the middle is PC " on which I can change value of slider ( what i want is slider is on the same position on PC and on phone ) And format of a slider is different than data from sensors
Regards
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
I'm connected with RPI which is being connected with plc.
Plc is sending data to Rpi and Rpi is connected with the app .
App is reading values from sensors every each second ( pressure, temp, etc... ) . " Man in the middle is PC " on which I can change value of slider ( what i want is slider is on the same position on PC and on phone ) And format of a slider is different than data from sensors
Regards
You can send as many values as you want in one String for example:
B4X:
Dim SendString as String = "VAL.33, VAL.44, VAL.105, VAL.88 ....."
And on the receiving end you can parse them like this:
B4X:
Dim ReceivedString() As String = Regex.Split(",", inputstr)
inputstr would be the string received, the ReceivedString() would contain however many values you sent, ReceivedString is an Array of Strings, in this case it will contain all the values you sent, in my code above let's say i only sent 4 values.
ReceivedString(0) would be "VAL.33"
ReceivedString(1) would be "VAL.44:
ReceivedString(2) would be "VAL.105"
ReceivedStrinig(3) would be "VAL.88"

Hope this helps.
Walter
 
Upvote 0

Pepebis

Member
Licensed User
Dear Walter ,
I CAN'T I'm not changing the value of slider often. I want to send this like another string and parse this in another way.Don't forget strings from sensors coming every sec. Is it possible?
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Dear Walter ,
I CAN'T I'm not changing the value of slider often. I want to send this like another string and parse this in another way. Is it possible?
I don't think you are being very clear about what you are trying to accomplish here.

Walter
 
Upvote 0

Pepebis

Member
Licensed User
Ok . Try imagine I'm sending strings from few sensors at the same time.
from Tem from hum and from pressure ...etc .
On each of them, I'm putting prefix (something like this : ( TEM. 22.1 ) ( PRE.32.31) ( FLO33.3) .
How I can do a thing to set values of each of them to proper gauges?
Best Regards , Semek
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
Ok . Try imagine I'm sending strings from few sensors at the same time.
from Tem from hum and from pressure ...etc .
On each of them, I'm putting prefix (something like this : ( TEM. 22.1 ) ( PRE.32.31) ( FLO33.3) .
How I can do a thing to set values of each of them to proper gauges?
Best Regards , Semek
Are you sending all the Values of the different sensors in one String, or are you sending them separately, if you are sending them all in one string, the code i posted above will work, if you are sending them separately then you can just look for the prefix, it would be helpful to know what library you are using to send sensor data, are you using bluetooth connection, are you using Serial connection etc..

Walter
 
Upvote 0

Pepebis

Member
Licensed User
I'm sending them in one string, and it's working. But.... i want to send in the same time another one. AND that is my problemo .
 
Upvote 0

walterf25

Expert
Licensed User
Longtime User
I'm sending them in one string, and it's working. But.... i want to send in the same time another one. AND that is my problemo .
Show me the code where you are sending the sensor data.
 
Upvote 0

Pepebis

Member
Licensed User
Dear Walter ,
Sending is not an issue ( I think I'm not clear )
Sub udp_send ( dane As String , ip As String , port As String )

If ip <> Null Or ip<>"" Then

Dim data() As Byte
Dim udppack As UDPPacket
data= dane.GetBytes("UTF8")
udppack.Initialize(data,ip,port)
udp.Send(udppack)

edLOG.Text = edLOG.Text & ">"& dane.Trim & CRLF
edLOG.SelectionStart = edLOG.Text.Length

End If



End Sub
 
Upvote 0

kisoft

Well-Known Member
Licensed User
@walterf25,
B4X:
ReceivedString (0) to „VAL.33”
This is a mistake. Regex doesn't index from zero, it indexes from 1
B4X:
ReceivedString (1)
@Pepebis
put the code in the appropriate tags

Send it all in one go. All you have to do is form it properly. Create the right values between the separators. The separator can be any character (almost any) in this example is "*".
B4X:
    Dim str As String = "*31.1*32.2*33.3*34.4*"
    Dim str1,str2,str3,str4 As String
    Dim numbers() As String
    numbers = Regex.Split("\*", str)
    str1=numbers(1)
    str2=numbers(2)
    str3=numbers(3)
    str4=numbers(4)
If you don't want to change the settings every second, send an empty character or prefix. Now you can get the desired action using conditional statements or select case etc.
 
Last edited:
Upvote 0
Top