Git Product home page Git Product logo

Comments (8)

boblemaire avatar boblemaire commented on July 29, 2024

Just to be clear, an instance of this class can only handle one request at a time. That said:

One solution is to simply change the callback to a different appropriate function prior to each request.

Another solution is to use the callback parameter to point to something that can be used to differentiate between the various requests.

from asynchttprequest.

Rollmops67 avatar Rollmops67 commented on July 29, 2024

Hello and thank you for the fast answer !

Not knowing very well AsyncHTTPrequest and it different syntaxes (there is not much information) your 2 propositions are not of big help...

Change the callback to a different appropriate function, why not, but there are not many examples I can look how to do, and what function to use...

I think that your second solution is maybe related to the "void* optparm" option in the "void requestCB" function ?
But I tried to figure out how it works but I can't find where this "optparm" is defined and how to redirect (??) the callback with it.
Do you maybe have an example ?

TIA !

Roland

from asynchttprequest.

boblemaire avatar boblemaire commented on July 29, 2024

Maybe something like this:

// First request
void sendRequest_0()   // to gather the responseText() for the "Pedf" value
{
    if(request.readyState() == 0 || request.readyState() == 4)
    {
        request.onReadyStateChange(request1CB);
        request.open("GET", "http://192.168.1.12/emeter/0");
        request.send();
    }
}



void sendRequest_1()   //    // to gather the responseText() for a second value
{
    if(request.readyState() == 0 || request.readyState() == 4)
    {
        request.onReadyStateChange(request2CB);
        request.open("GET", "http://192.168.1.12/emeter/1");
        request.send();
    }
}

void request1CB(void* optparm, asyncHTTPrequest* request, int readyState)
{
    if(readyState == 4)
    {
 //       Serial.println(request->responseText());
        Pedf = atof(((request->responseText()).substring(9,18)).c_str());
        Serial.println(Pedf);
    }
}

void request2CB(void* optparm, asyncHTTPrequest* request, int readyState)
{
    if(readyState == 4)
    {
 //       Serial.println(request->responseText());
        Pedf = atof(((request->responseText()).substring(9,18)).c_str());
        Serial.println(Pedf);
    }
}

from asynchttprequest.

Rollmops67 avatar Rollmops67 commented on July 29, 2024

Ohhh thanks.

Ah, its the "request.onReadyStateChange(requestxxx);" wich does the magic !

i will try it.

Roland

from asynchttprequest.

Rollmops67 avatar Rollmops67 commented on July 29, 2024

I just tried it, with the result that the ESP32 crashes each time the 2 requests are launched at the same time.
I changed my code so the first request starts every 5 seconds, and the second request 2,5 seconds after, and now it works !

Many many thanks !

Roland

from asynchttprequest.

Rollmops67 avatar Rollmops67 commented on July 29, 2024

Edit :

Oooops,
After about 10 minutes it crashed, with a guru meditation error :

23:24:01.076 -> Guru Meditation Error: Core  1 panic'ed (InstrFetchProhibited). Exception was unhandled.
23:24:01.076 -> 
23:24:01.076 -> Core  1 register dump:
23:24:01.076 -> PC      : 0x00440022  PS      : 0x00060930  A0      : 0x820044f1  A1      : 0x3fca6b50  
23:24:01.076 -> A2      : 0x3fca2b78  A3      : 0x40010000  A4      : 0x3fca2b70  A5      : 0x0000000c  
23:24:01.076 -> A6      : 0x02c95354  A7      : 0x00ffffff  A8      : 0x820043f5  A9      : 0x3fca6b40  
23:24:01.076 -> A10     : 0x3fca2b78  A11     : 0x3fca6b5c  A12     : 0x3fca6b58  A13     : 0x00000000  
23:24:01.076 -> A14     : 0x00000001  A15     : 0x3fca2d40  SAR     : 0x0000000a  EXCCAUSE: 0x00000014  
23:24:01.076 -> EXCVADDR: 0x00440020  LBEG    : 0x400570e8  LEND    : 0x400570f3  LCOUNT  : 0xffffffff  
23:24:01.076 -> 
23:24:01.076 -> 
23:24:01.076 -> Backtrace: 0x0044001f:0x3fca6b50 0x420044ee:0x3fca6b80 0x42004504:0x3fca6ba0 0x4200481e:0x3fca6bc0
23:24:01.076 -> 
23:24:01.076 -> 
23:24:01.076 -> 
23:24:01.076 -> 
23:24:01.076 -> ELF file SHA256: a65d66640a0063d8
23:24:01.076 -> 
23:24:01.076 -> Rebooting...
23:24:01.076 -> ESP-ROM:esp32s3-20210327
23:24:01.076 -> Build:Mar 27 2021
23:24:01.076 -> rst:0xc (RTC_SW_CPU_RST),boot:0x8 (SPI_FAST_FLASH_BOOT)
23:24:01.076 -> Saved PC:0x420195f5
23:24:01.076 -> SPIWP:0xee
23:24:01.076 -> mode:DIO, clock div:1
23:24:01.076 -> load:0x3fce3808,len:0x44c
23:24:01.076 -> load:0x403c9700,len:0xbe4
23:24:01.076 -> load:0x403cc700,len:0x2a38
23:24:01.076 -> entry 0x403c98d4

Roland

from asynchttprequest.

boblemaire avatar boblemaire commented on July 29, 2024

Simultaneous requests work with the ESP8266. The ESP32 is a different animal. I don't use this with ESP32 because there is really no need to provide the asynchronous HTTP functionality with ESP32. You can just create a FREERTOS task to do the transaction with either HTTPclient or the underlying esp_http_client and blocking will only affect that task while your other tasks continue to execute. You get the added benefit of being able to use both processors.

from asynchttprequest.

Rollmops67 avatar Rollmops67 commented on July 29, 2024

OK, I will try this way.

Thanks for the time spend.

Roland

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.