Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Luiz Henrique
#54262
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
User avatar
By Luiz Henrique
#56715
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;
}