Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
If wifi.Connect("esp_server") = False Then
Log("Error connecting to network")
Return
Else
Log("Connected to network")
End If
RunNative("SetSTA", Null)
usocket.Initialize(51042, "usocket_PacketArrived")
Timer1.Initialize("Timer1_Tick", 50)
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick
Timer1.Enabled = False
' The Sub Below "Read Data" was called to Read the Device and Populate the Array that was sent to the Esp Server every 50 ms in Timer1_Tick
Read_Data
' ******************************** I used sizeof to determine it was 18 bytes and checked for the receiving side
usocket.BeginPacket(ip, port)
usocket.Write(ser.ConvertArrayToBytes(Array(X_axis, Y_axis, C_button, Z_button, X_acc, Y_acc, Z_acc)))
usocket.SendPacket
Timer1.Enabled = True
End Sub
Private Sub usocket_PacketArrived (Data() As Byte, ip1() As Byte, port1 As UInt)
'not used
Log("Packet arrived")
End Sub
#if C
void SetSTA(B4R::Object* o) {
WiFi.mode(WIFI_STA);
}
#end if