I'm creating a person counter, just simply counting the In/Out in room then upload it on my database, I'm using Arduino MEGA2560 with ESP8266 as communicator to my server.
But I'm having trouble when I send a HTTP GET request on my server. Once I send HTTP GET request my counter function wont work until HTTP GET request is done, Just wondering if there's such as async function here in Arduino that is easy to use and under stand, or there's a right way using HTTP GET request
Here's my code:
void 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 /vbus/insert.php?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));
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");
}
}
PS: I don't have any problem sending HTTP GET request just the one above I said.