-->
Page 4 of 6

Re: Skip HTTP Header from GET request

PostPosted: Thu Sep 01, 2016 10:41 am
by Luiz Henrique
martinayotte wrote:
Luiz Henrique wrote:This code really works for me, BUT i need a other trouble.
I need to use a decision with a my response.

Code: Select all    String tratado = resposta;
    if (tratado="OFF")


In my case, he always print "OFF". typing same ON or OFF. I need to clear the buffer or the cache always in end of loop? How i can do this?


I think you need to learn a bit more about C/C++ ... :ugeek:
The code " if (tratado="OFF") " totally doesn't do what you wish.
You may use double equals, but since maybe other characters can follow the OFF, such \r\n, the equal probably won't succeed either. You need to do " if (resposta.startWith("OFF")) " instead.


Hmmm, i understand. Srry for my bad. I will test tonight and i tell u

Re: Skip HTTP Header from GET request

PostPosted: Thu Sep 01, 2016 1:31 pm
by martinayotte
I did a small type, it should be : tratado.startWith("OFF" )

Re: Skip HTTP Header from GET request

PostPosted: Tue Oct 18, 2016 3:28 pm
by Luiz Henrique
martinayotte wrote:I did a small type, it should be : tratado.startWith("OFF" )


Martin, after this time, my code doesn't receive data anymore.
I get the data from Node.js, i test and its ok in node side.
But in ESP8266, i cant receive anything with this code:

Code: Select all  uint8_t buffer[1024] = {0};

    if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
        Serial.print("connection with host OK\r\n");
    } else {
        Serial.print("Error connection Host\r\n");
    }

    char *ComandoGET = "GET /StatusSaidas HTTP/1.1\r\nConnection: close\r\n\r\n";
    wifi.send((const uint8_t*)ComandoGET, strlen(ComandoGET));

    uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
    char *resposta = buffer;
    for (int i = 0; i < len; i++)
    {
        if (strncmp(resposta++, "\r\n\r\n", 4) == 0) break;
    }
    resposta += 3;
    String tratado = resposta;
}

Re: Skip HTTP Header from GET request

PostPosted: Tue Oct 18, 2016 4:09 pm
by martinayotte
Do you mean that the body is empty ?
Did you try to print it ?
Which framework are you using ?
Maybe String initialisation isn't done properly, do it that way instead :
Code: Select allString tratado = String(resposta);