Android Question UDP _seekbar

MJbidram

New Member
Hello
I want to control two LEDs by connecting UDP to two seekbars. But I do not know what command to use to send values so that each LEd is controlled separately.
The code I wrote sends values with the udp protocol, but because the values sent are the same name, both LEDs are controlled by changing a seekbar. How can I send a name along with the sent bytes so that the recipient of the message notices the seekbar change.
My code is as follows:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    
    Dim server As UDPSocket
    
    
End Sub

Sub Globals
    
    Private IP As EditText
    Dim s1 As ServerSocket
    Private SeekBar1 As SeekBar
    Private Label2 As Label
    Private SeekBar2 As SeekBar
End Sub

Sub Activity_Create(FirstTime As Boolean)
    
    Activity.LoadLayout("1")
    server.Initialize("server",12000,300)
    Activity.Title=s1.GetMyIP
    
End Sub

Sub server_PacketArrived (Packet As UDPPacket)
    
    Label2.Text=(BytesToString(Packet.Data,0,Packet.Length,"utf-8"))
    
End Sub


Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub


Sub SeekBar1_ValueChanged (Value As Int, UserChanged As Boolean)
    Dim b1 As ByteConverter
    Dim b2 As String
    b2 = SeekBar1.Value
    Dim p4 As UDPPacket
    p4.Initialize(b1.StringToBytes(b2,"utf-8"),IP.Text,12000)
    server.Send(p4)
    
    
    
    
End Sub

 
Sub SeekBar2_ValueChanged (Value As Int, UserChanged As Boolean)
    Dim b1 As ByteConverter
    Dim b2 As String
    b2 = SeekBar1.Value
    Dim p5 As UDPPacket
    p5.Initialize(b1.StringToBytes(b2,"utf-8"),IP.Text,12200)
    server.Send(p5)
End Sub
 

MJbidram

New Member
I am using the nodemcu module.
That is, the values sent from each seekbar are read by the Arduino.
I do not know what command to use in b4a to be able to separate the values sent by seekbar1, seekbar 2
 
Upvote 0

MJbidram

New Member
Arduino code receives the packet and converts it to a string. In Arduino we can add an extension called the received packet to read only the data sent with the same name.
But I do not know how to separate these codes in b4a.
Let me ask my questions with an example:
I want to write a program that sends information to another Android device (with UDP protocol) via 2 seekbar. Can you give me these codes ???
I really need this code. Thank you if you can help me.
I can not type well in English and use a translator.
 
Upvote 0

kisoft

Well-Known Member
Licensed User
Longtime User
If it is a string then you can use the reg method regex. You just need to form the appropriate string in Arduino and then in B4 properly extract the data using one of the following methods
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…