boblemaire / asyncHTTPrequest

asynchronous HTTP for ESP using ESPasyncTCP. Works like XMLHTTPrequest in JS.
GNU General Public License v3.0
65 stars 31 forks source link

Hello #7

Closed ryannining closed 5 years ago

ryannining commented 5 years ago

looks promising for my project, an ESP 3d controller that download Gcodes from my server , or to report to server. Currently i am using standard httpclient library and its pause the machine every time its report to server using http client.

    if (cmd == "print") {
      zprintf(PSTR("Download & Print:\n"));
      String durl = "http://172.245.97.171/download?gid=" + par;
      File f = SPIFFS.open("/gcode", "w");
      if (f) {
        http.begin(durl);
        int httpCode = http.GET();
        if (httpCode > 0) {
          if (httpCode == HTTP_CODE_OK) {
            Serial.println(durl);
            Serial.println(http.getSize());
            http.writeToStream(&f);
          }
        } else {
          zprintf(PSTR("Error download"));//[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }
        http.end();
        f.close();
        beginuncompress();
      }
    }

but i am confuse how to implement it on async. can you help me ?

thanks.

boblemaire commented 5 years ago

Can't really help you here. Async isn't really a plug replacement for sync, at least not if you want to realize the benefits of async. In general it would require a restructuring of your program to do other things while waiting for the request to complete. There is the capability to attach a handler to either state change or data receipt, so that could be done with minimal change to your program, but you still need to synchronize somehow after the request completes before doing another request.