Thank you very much, Erel!
However, I am still too dummy to get it working with my original ESP8266 Wifi server, which is just sending numeric strings all the time...
1. I can modify your B4i sample and build it ok to my iPhone.
However, unlike my B4a version, the connection to my ESP8266 Wifi server is no longer static but broken easily and I don't see any trigger to AStream_NewData() tor receive the hard-coded numeric string like "123" even though I already simplified it into:
Sub astream_NewData (Buffer() As Byte)
Dim Rx_String As String
Rx_String = BytesToString(Buffer, 0, 4 , "UTF8")
edtName.Text = Rx_String
End Sub
2. Since I could not the Rx side working, I decided to modify the Tx side to see if my ESP8266 Wifi Server can receive from B4i app.
Again, I simplified:-
Sub btnSend_Click
Dim conv As ByteConverter
Dim data() As Byte = conv.StringToBytes(edtName.Text, "UTF8")
SendData(data)
End Sub
so when I put "12345" in the edtName.Text and press "Send",
I can see from the ESP8266 UART log that a special character + "12345" got received.
I am curious if I can remove the special character at the beginning easily?!
But I verified that the Send function is ok in B4i, not the Receive function I need.
Any other suggestion please?
If possible, I would like to preserve my ESP8266 Wifi server code the same for both B4a and B4i app
but if it's not possible, I will try to modify my ESP8266 code then.
My ESP8266 code is again pretty straight-forward if I just send hard-coded data out to B4a and B4i app:
void loop() {
client1 = server1.available();
String readString;
// Wait until the client sends some data
Serial.println("new client");
while( client1.connected() )
{
char buffer[10];
//Hard-coded string to be sent to B4a & B4i app for testing
readString = "S123";
if (readString.substring(0,1) == "S")
{
char charBuf[4];
int count = 0;
readString.substring(1).toCharArray(charBuf, 4) ;
for (int i=0; i<readString.length(); i++)
{
if (isDigit(charBuf[i]))
{
count++;
}
}
if (count == readString.length()-1)
{
distance = atoi(&charBuf[0]);
}
snprintf(buffer,5,"%4d",distance);
client1.print(buffer); // Sending "123" to B4a & B4i app, B4a - OK but not B4i
client1.flush();
}
readString="";
} // while (client.connected)
Serial.println("new client disconnected");
client1.stop();
}
Thanks & Best Regards,
Robert