-->
Page 1 of 1

Is it possible HTTP GET Request Non-Blocking?

PostPosted: Fri Mar 24, 2017 12:29 am
by Paulernest
I'm using ESP8266-01 with Arduino Mega2560, But I'm having trouble with sending HTTP GET Request without blocking my other function. is it possible?
I'm using library https://github.com/itead/ITEADLIB_Arduino_WeeESP8266.
Here's my code.

Code: Select allvoid loop{
    counter(); // let's assume that this function is just counting in and out person in the room
    // changing the value of variable count
    uint8_t buffer[1024] = {0};

    if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
        Serial.print("create tcp ok\r\n");
    } else {
        Serial.print("create tcp err\r\n");
    }

    char hello[];
    strcpy(hello, "GET /indexphp?coount=");
    strcat(hello, count);
    strcat(hello," HTTP/1.1\r\nHost: www.test.com\r\nConnection:close\r\n\r\n");
    wifi.send((const uint8_t*)hello, strlen(hello));

    uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
    if (len > 0) {
        Serial.print("Received:[");
        for(uint32_t i = 0; i < len; i++) {
            Serial.print((char)buffer[i]);
        }
        Serial.print("]\r\n");
    }
}


when I'm creating TCP,releasing TCP and
Code: Select all wifi.send();
my counter() is blocked until the request is finish so I didn't monitor the In and Out while I'm sending a data on my server.