I am trying to set a UDP broadcast address derived from the string returned by wifi.localIP and understand I'll need to use GlobalStore slots as a means of transferring variable data between subs. Below is the code, with the two commented lines being the problematic ones:
While I can split out the elements of the IP address:
and while:
passes the broadcast address successfully to:
all variants of:
which I've tried to create the IP address array dynamically from the collected elements do not work.
B4X:
Sub Process_Globals
Public Serial1 As Serial
Private usocket As WiFiUDP
Private wifi As ESP8266WiFi
Private port As UInt = 3661
Private astream As AsyncStreams
Private bc As ByteConverter
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
astream.Initialize(Serial1.Stream, "astream_NewData", "astream_Error")
If wifi.Connect2("Telstra1943", "********") = False Then
Log("Error connecting to network")
Return
Else
Dim index As UInt = 1
For Each s() As Byte In bc.Split(wifi.localIP, ".")
Log(s)
GlobalStore.Put(index, s)
index = index + 1
Next
' GlobalStore.Put(0, Array As Byte(192, 168, 0, 255))
' GlobalStore.Put(0, Array As Byte(GlobalStore.Slot1, GlobalStore.Slot2, GlobalStore.Slot3, 255))
End If
usocket.Initialize(51042, "usocket_PacketArrived")
End Sub
Sub astream_NewData (Buffer() As Byte)
usocket.BeginPacket(GlobalStore.slot0, port)
For Each s() As Byte In bc.Split(Buffer, CRLF)
If s.Length <> 0 Then
usocket.Write(s)
usocket.SendPacket
End If
Next
End Sub
While I can split out the elements of the IP address:
B4X:
Dim index As UInt = 1
For Each s() As Byte In bc.Split(wifi.localIP, ".")
Log(s)
GlobalStore.Put(index, s)
index = index + 1
Next
and while:
B4X:
GlobalStore.Put(0, Array As Byte(192, 168, 0, 255))
passes the broadcast address successfully to:
B4X:
usocket.BeginPacket(GlobalStore.slot0, port)
all variants of:
B4X:
GlobalStore.Put(0, Array As Byte(GlobalStore.Slot1, GlobalStore.Slot2, GlobalStore.Slot3, 255))
which I've tried to create the IP address array dynamically from the collected elements do not work.