1

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.

5
  • Are you using arduino fw within esp8266? You have arduino-esp8266 tag in the question. Commented Mar 20, 2017 at 6:56
  • I'm using arduino with esp8266, If my tag is incorrect please correct me :) Commented Mar 20, 2017 at 8:00
  • No, no problem. Just trying to figure out of you are using arduino fw on esp8266 Commented Mar 20, 2017 at 8:03
  • As long as you are using serial library for connectivity, you will not be flexible enough to have support on these kind of issues. ESP8266 Arduino firmware has an async HTTP library, fyi. Commented Mar 20, 2017 at 11:57
  • @cagdas can you tell me what is fw, I'm just a beginner please forgive me :), so you're telling me better if I use a serial.write AT command? Commented Mar 21, 2017 at 2:16

2 Answers 2

5

For those, who are visiting this post later than 2017:

You can use this library for this case: ESP8266AsyncHttpClient

It's a asynchronous HTTP client for the ESP8266 that uses the ESPAsyncTCP library.

It is written by me and you only can send requests but you cannot yet get the response back for further processing. But i will implement it in the future.

Sign up to request clarification or add additional context in comments.

Comments

1

This kind of serial libraries are far away from flexibility for your custom requests. While you are using your ESP8266 device over serial, there is an embedded software on it to handle your requests. That is the firmware.

If you use the AT commands, it will not help your case hence there is no non-blocking TCP implementation on it to handle the async HTTP requests.

There is a solution comes with async TCP library for Arduino based ESP8266 users, where you can adapt your code base on it, and here is the sake of flexibility.

9 Comments

Hi, when I'm trying to compile the sample program I'm getting this error. C:\Users\zxcet\Documents\Arduino\libraries\ESPAsyncTCP-master\src/ESPAsyncTCP.h:27:22: fatal error: functional: No such file or directory #include <functional> ^ compilation terminated. exit status 1 Error compiling for board Arduino/Genuino Mega or Mega 2560.
This is for esp8266 device. You will directly program the ESP8266, not the arduino mega. So you need to import esp8266 as device from board manager.
If arduino mega is required for your case, you may need also make a serial connection but with writing your own protocol and calling woth your own functions. A lil bit tough indeed.
In my case I need arduino badly, I'm using other modules not just wifi, but thank you for enlightening me in my case. I'm just giving this a try
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.