How can parse answer from server?


When i send Get to my server respond this:

HTTP/1.1 200 OK
Date: Fri, 31 Jan 2020 23:26:41 GMT
Server: Apache/2.4.41 (Win64) OpenSSL/1.1.1c PHP/7.4.1
X-Powered-By: PHP/7.4.1
Content-Length: 107
Content-Type: text/html; charset=UTF-8
Connection: close


How can i save all this on a variable?
Ans how can i parse one variable to one value?



valnMin = 1
valnN1 = 1
valnN2 = 0 

Thx very much ^^

If it is your server, a key thing to do is to send the data in a format that is easy to parse. Packet start/end markers, data delimiters, and timing can be used. If you use the forum search for "parse data" and similar, you will probably find many different methods.

You might be able to use something similar to the below using the "|" as a packet delimiter.

//zoomkat 11-12-13 String capture and parsing  
//from serial port input (via serial monitor)
//and print result out serial port
//copy test strings and use ctrl/v to paste in
//serial monitor if desired
// * is used as the data string delimiter
// , is used to delimit individual data 

String readString; //main captured String 
String angle; //data String
String fuel;
String speed1;
String altitude;

int ind1; // , locations
int ind2;
int ind3;
int ind4;
void setup() {
  Serial.println("serial delimit test 11-12-13"); // so I can keep track of what is loaded

void loop() {

  //expect a string like 90,low,15.6,125*
  //or 130,hi,7.2,389*

  if (Serial.available())  {
    char c =;  //gets one byte from serial buffer
    if (c == '*') {
      //do stuff
      Serial.print("captured String is : "); 
      Serial.println(readString); //prints string to serial port out
      ind1 = readString.indexOf(',');  //finds location of first ,
      angle = readString.substring(0, ind1);   //captures first data String
      ind2 = readString.indexOf(',', ind1+1 );   //finds location of second ,
      fuel = readString.substring(ind1+1, ind2+1);   //captures second data String
      ind3 = readString.indexOf(',', ind2+1 );
      speed1 = readString.substring(ind2+1, ind3+1);
      ind4 = readString.indexOf(',', ind3+1 );
      altitude = readString.substring(ind3+1); //captures remain part of data after last ,

      Serial.print("angle = ");
      Serial.print("fuel = ");
      Serial.print("speed = ");
      Serial.print("altitude = ");
      readString=""; //clears variable for new input
    else {     
      readString += c; //makes the string readString

If you're trying to communicate with a server, the standard is to use JSON responses. It already takes care of the delimiting mentioned in the previous replies.

Have you ever wanted to integrate a 3rd Party Client with your SashiDo applications? I suppose you have, and there's an awesome feature called WebHooks which help you do just that. In simple terms, a WebHook allows any 3rd Party Client, that supports Webhooks check myprepaidcenter balance

what are you using, an UNO with an ETH shield or any kind of ESP8266?

How can i save all this on a variable?

read character by character until a linefeed in a buffer.
check if you have an "empty" line - this will be the marker between the HTTP-header and HTTP-body.
if it was a line of the HTTP-header throw it away and start again reading the next line
it it was a line of the HTTP-body use the linebuffer in the next step to parse your data.

Ans how can i parse one variable to one value?

you should read about


at the moment no much luck..

I am trying with this :

  if (cadena2.indexOf("val") > 0)
    String dnMin, dnN1, dnN2, dnMax, dnAlarma, dvalestadoB1, dvalestadoB2, dvalordenB1, dvalordenB2;
    int ind1, ind2, ind3, ind4;
    ind1 = cadena2.indexOf('|');
    ind2 = cadena2.indexOf("|","|");
    dnMin = cadena2.substring(ind1+1, 10);
    dnN1 = cadena2.substring(ind2);
    cadena2 = "";

Need parse this:


only work the fist one...


That response would be absolutely trivial to parse using strtok - much simpler than using dozens of subString and indexOf calls. Google "c strtok()".

Ray L.

well to trying with that :

    char buf;
    unsigned int len;
    cadena2.toCharArray(buf, len);

    //    dnMin = strtok(buf, '|');
    //    dnN1 = strtok(buf, '|');

    char *strings[10];
    char *ptr = NULL;
    byte index = 0;

    ptr = strtok(buf, '|');  // takes a list of delimiters
    while (ptr != NULL)
      strings[index] = ptr;
      ptr = strtok(NULL, '|');  // takes a list of delimiters
    // print the tokens
    for (int n = 0; n < index; n++)

but dont print nothing, to see if are working or no…
and was need convert String to char first…

No progresion atm :frowning:
i think, programming are not my …

A problem with the below data format is there appears to be no start or end markers for the data packet, if this is a data packet. The ease of data capture and parsing may depend on several things. The issue will probably be the same using Strings, or C-strings. Do you have any control over how the data is packaged and the timing of the sending?


...or use JSON

...or use JSON

So you got example code? Just curious.

Several problems with that code snippet.

First, you do NO checking that buf is large enough, before copying to it. You are very likely clobbering your memory, right off the bat.

Second, you do not initialize len but pass it as a parameter to toCharArray, so who knows what the result of executing that line is. Again, you are very likely clobbering your memory, right off the bat.

Third, I've never used Strings, and suspect toCharArray() copies the characters, but NOT the trailing NULL that marks the end of the c-style string. So, strtok has no way of knowing where the end of the input string is.
Instead of String.toCharArray(), you should be using String.c_str().

Fourth, you do NO checking that strings contains enough pointers to holds all the tokens strtok parses from the input string.

Ray L.

I finally do ti with that:
but i dont sure if are correct, but it work:

 if (cadena2.indexOf("val") > 0)
    //String dnMin, dnN1, dnN2, dnMax, dnAlarma, dvalestadoB1, dvalestadoB2, dvalordenB1, dvalordenB2;

    int posc = 0; //posicion de cadena2
    int posa = 0; //la posicion del caracter dentro de array dvalores (desde 0 a 8 = 9 )

    memset(dvalores, '\0', 9); //inicializacion del array

    while (posc <= cadena2.length() && posa <= 8)                      //bucle mientras que sea menor que la logitud de cadena2
      while (cadena2.charAt(posc) != '=' and posc <= cadena2.length()) //bucle bsuca el = dentro de cadena2
        posc++;                                                        //suma uno al contador
      if (posc <= cadena2.length())                                    //si no es el final de cadena2...
        dvalores[posa] = cadena2.charAt(posc + 1) - '0';               //guarad el siguiente valor al = en dvalores

    Serial.print("Valores Finales: ");
    for (int c = 0; c <= 8; c++)                                  //mostrar resultados //mientras (inicializacion; condicion de terminar; suma uno por cada loop)
    cadena2 = "";

tell my plz is see something wrong