Git Product home page Git Product logo

Comments (3)

Hello1024 avatar Hello1024 commented on July 29, 2024

Looks like this might be the answer:

asyncHTTPrequest request;

void setup() {
  Serial.begin(9600);
}

void loop() {
      // start request
      request.open("GET", "http://worldtimeapi.org/api/timezone/Europe/London.txt");
      request.send();

      // Print dots while request in progress
      while (request.readyState() != 4) {
        delay(100);
        Serial.print('.');
      }

      // Check there was no error and print result
      if (request.responseHTTPcode() == 200)
          Serial.println(request.responseText());

      delay(5000);
}

from asynchttprequest.

Hello1024 avatar Hello1024 commented on July 29, 2024

Note that the above is rather complex - it would be nice to have a 'simple' static API which looks like this:

void setup() {
  Serial.begin(9600);
}

void loop() {
      auto req = asyncHTTPrequest.start("http://worldtimeapi.org/api/timezone/Europe/London.txt");

     // do stuff while waiting
     while (!req.done) delay(100);

    if (req.success) Serial.println(req.responseText());
}

from asynchttprequest.

boblemaire avatar boblemaire commented on July 29, 2024

I've added a simple example that makes requests to the worldtimeapi above. However the example doesn't sit in a wait loop waiting for completion. That would defeat the purpose.
The most recent comment above suggests changing the actual methods of the class. That is doable, and I recommend that you fork the repo and make a new class for that.
I made this class to use in one of my other repositories "IoTaWatt" because there was no good way to have an async client and I desperately needed one. It fulfills my needs. Also, take a look at the subsidiary xbuf, which probably should be in it's own repo as it has come in handy for all manner of buffering and manipulation.
I would entertain any PRs to improve this class, but the risk would have to be low and it would need to be well tested as IoTaWatt is in use in thousands of sites worldwide.

from asynchttprequest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.