I'm trying to parse out a message received from a sever where the Arduino is the client. The message consists of numbers and letters and is split based on spaces and ";" - such as "s112; 223; set; 32s ". When I run my code and the server send the message it prints a few blank lines and that is it. I have tried by assigning the string to Msg and it printed out as I expected. I think I am having trouble where I convert char serverMsg = client.read(); to String Msg = String(serverMsg); as I think it only reads one character at a time that way and I am unsure of going about it any other way.
Here' the code!
if (client.available()) {
char serverMsg = client.read();
String Msg = String(serverMsg);
String parsedMsg[50];
int r = 0, t = 0;
for (int i = 0; i < Msg.length(); i++)
{
if (Msg[i] == ' ' || Msg[i] == ';')
{
if (i - r > 1)
{
parsedMsg[t] = Msg.substring(r, i);
t++;
}
r = (i + 1);
}
}
for (int k = 0; k <= t; k++)
{
Serial.print(parsedMsg[k]);
}
}