Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Mar 30 22:22
    stale[bot] closed #663
  • Mar 30 22:22
    stale[bot] commented #663
  • Mar 30 17:10
    BlueAndi commented #731
  • Mar 30 17:09
    BlueAndi commented #731
  • Mar 30 17:06
    BlueAndi commented #731
  • Mar 30 00:43
    Paytah232 commented #731
  • Mar 29 20:43
    BlueAndi commented #731
  • Mar 29 19:46
    stale[bot] labeled #691
  • Mar 29 19:46
    stale[bot] commented #691
  • Mar 29 13:13
    Paytah232 commented #731
  • Mar 29 12:38
    BlueAndi commented #731
  • Mar 29 10:46
    stale[bot] labeled #689
  • Mar 29 10:46
    stale[bot] commented #689
  • Mar 29 01:44
  • Mar 28 18:40
    0xFEEDC0DE64 edited #732
  • Mar 28 18:39
    0xFEEDC0DE64 opened #732
  • Mar 28 11:52
    CircuitSetup commented #694
  • Mar 28 11:15
    stale[bot] closed #675
  • Mar 28 11:15
    stale[bot] commented #675
  • Mar 28 10:27
    Paytah232 opened #731
trailblazr
@trailblazr
@sparkplug23 I have also added a BUILD flag CORS_INSECURE for testing JavaScript cross site, to be able to test my HTML locally on the computer running Javascript loaded from my local directory, but requesting stuff from the micro controller powered Webserver. This is normally NOT allowed. I did add this to my main.cpp to overcome this hurdle. But do not forget to deactivate it on deployment. ;-)
  #ifdef CORS_INSECURE
  // ALLOW CROSS SITE JAVASCRIPT ACCESS (CORS) BY DEFAULT
    DefaultHeaders::Instance().addHeader("Access-Control-Allow-Origin", "*");
  #endif
Michael
@sparkplug23
Ah yes, again I am trying to fix one thing with all the previously pieces commented out. I did have onNotFound it just had not been migrated the async yet (it is now ;) )
Yeah, I am just using postman to check the building of json responses etc. Short term I am going to have quite a few responses until I ultimately make the page almost all one solid char array. If I can work out how to append scripts or send them as extra urls etc then I wont need to transmit them during the initial page load.
In regards to cors_insecure, I actually did have that enabled, I seen it in a project that was listed as using async that I am using as an example, I didn't fully grasp what it was doing until you just said. Ill leave it for now, but definitely a security hole to patch.
thanks for the great advice, its very much appreciated. It's going to be a long road of redesigning my code but I know the end result will be worth it.
I am currently getting mixed results, sometimes the page loads, sometimes it crashes the board. Probably a rogue pointer.
Michael
@sparkplug23
Does chunkedresponse actually send on each return (when not 0) or does it wait until 0 THEN send it in chunks using the buffer pointers returned for each chunk?
Michael
@sparkplug23
Back to basics, if I had say 3 char arrays stored in memory, I assumed if I passed one at a time (from a function) with buffer* at the start, and returning its length as none zero, it would be okay? Its working sometimes, but mostly running into memory exceptions
Michael
@sparkplug23
I managed to get my 13kB main page down to about 3.5kB by moving styles and scripts as url loads. Seems fast and means I can use response print. hopefully it will work until I work out my new finalised root page that I can save as a large progmem. For some reason my sending chunked response was almost always crashing. I assume because others functions where called and any created arrays etc where going out of scope when the function was left. I'm not 100% sure how chunked response works so I'll avoid it for now.
Alexandr Zarubkin
@me21
Be warned, though, that the browser requests URLs in parallel, and this may lead to load failure if the number of requests is too high (4-5).
You cannot return pointer to the array which was allocated on stack and went out of scope, yeah. Allocate them in heap, not forgetting to delete them when needed, or use global/static arrays
Michael
@sparkplug23
@me21 Hey thanks. I won't have too many urls in parellel, its more a case of I needed a way to enable 1 per sensor/driver, so they will only added if its being used.
Michael
@sparkplug23
Is there a way to get the AsyncResponseStream size? Looking at the lib and I don't think so. Looking to check my size to check against freeheap space. For some reason I am able to build a response but its not sending over a limit, I want to check for that limit.
Vahe Arakelyan
@araqel_twitter
@me21 Привет, Александр! Могу я задать один вопрос про использование этой библиотеки?
Alexandr Zarubkin
@me21
Sure, go ahead
Vahe Arakelyan
@araqel_twitter
Please, advise how to get organized the click event transfer from client's side running browser to server side. It should be noticed that string, number, check box content delivering is not problem. Just need to deliver the click event.
Asyncronously, without page reload
Alexandr Zarubkin
@me21
There's onclick event handler for button, you can do whatever you want there. If you want no page reload, you can use AJAX (I think), websockets...
Vahe Arakelyan
@araqel_twitter
Could you, please, write out here the code, just important things on both side?
this is my button: <input type="button" name="inputBool" id="MyElement" onclick="changeClass()" value=%INPUTSTRING% >
The INPUTSTRING should be toggled from server side, between "On" and "Off"
Vahe Arakelyan
@araqel_twitter
being swithched by click event at client side
IVData
@IVData
Hey guys I have an issue. I'm serving static gzipped html files with ServeStatic, but I want to run some code each time a page is requested (to disable a bunch of expensive code also running). How can I do that?
I have tried using this, but get an Exception(28):
webServer.on("/index.html", [](AsyncWebServerRequest *request){
    enableDrawing = false;
    AsyncWebServerResponse* response = request->beginResponse(SPIFFS, "/index.html.gz", "text/html");
    response->addHeader("Content-Encoding", "gzip");
    request->send(response);
  });
Alexandr Zarubkin
@me21
@araqel_twitter not enough spare time to write code, sorry. I just know that AJAX and websockets are used for async client->server communication
trailblazr
@trailblazr

@IVData i read somewhere, on this chat, that if you store gzipped files on SPIFFS as e.g. index.html.gz it should automatically be served correctly as index.html to the client and have the header. No extra processing needed.

The Exception(28) looks more like a memory issue or too many requests hitting the webserver at the same time. I cannot overemphasize this, there is a really hard limit on how many requests the server can handle in parallel without wreaking havoc.

Michael
@sparkplug23
Hey guys. Is there a way (maybe I need to do it on the webpage side) to set a timeout, of I have a fetch that is pending and has starting to send but for some reason doesn't, the memory is not being freed up. When another message arrives sometime later, it uses more of the heap and eventually it overflows. Not sure why it's not sending, other calls are making their way through okay. And I am not longer hitting it hard, so it's not really an issue of that either.
zekageri
@zekageri
Hello everyone! Is it possible somehow to maintain a HTTPS connection with async lib?
Michael
@sparkplug23
Answering my own question, ended it with js
pablozg
@pablozg

Hi, I'm trying to do a async GET request every 2 seconds, It's working but I get a lot of "pcb is NULL" between request.

This is the request code:

static AsyncClient *aClient = NULL;

struct TCP_MESSAGE
{
    String message = "";
    uint16_t totalMessageLength = 0;
    uint16_t messageLength = 0;
    uint16_t headerLength = 0;
} message;

void runAsyncClient()
{
    if (aClient)
    { //client already exists
        return;
    }

    aClient = new AsyncClient();
    if (!aClient) //could not allocate client
        return;

    aClient->onError([](void *arg, AsyncClient *client, err_t error) {
        Serial.println("Connect Error");
        aClient = NULL;
        delete client;
    });

    aClient->onTimeout([](void *arg, AsyncClient *client, uint32_t time) {
        Serial.println("Timeout");
        aClient = NULL;
        delete client;
    });

    aClient->onDisconnect([](void *arg, AsyncClient *client) {
        Serial.println("Disconnected");
        aClient = NULL;
        delete client;
    });

    aClient->onConnect([](void *arg, AsyncClient *client) {
        Serial.println("Connected");
        // client->setRxTimeout(1);    //no RX data timeout for the connection in seconds
        // client->setAckTimeout(300); //no ACK timeout for the last sent packet in milliseconds

        String url;
        url = "GET /masterdata HTTP/1.1\r\nHost: " + (String)config.sensor_ip + "\r\nConnection: close\r\n\r\n";

        //send the request
        // Serial.println(url);
        if (client->space() > 32 && client->canSend()) {
            client->write(url.c_str());
        }
    });

    aClient->onData([](void *arg, AsyncClient *client, void *data, size_t len) {
        // Serial.print("\r\nData: ");
        // Serial.println(len);
        // Serial.println(String((char *)data));
        String chunk;

        chunk = String((char *)data);

        String i = midString(chunk, "Content-Length:", "\r\n");
        if (i != "")
        {
            message.totalMessageLength = i.toInt();
            message.headerLength = chunk.lastIndexOf("\r\n");
            message.messageLength = (int)len - message.headerLength - 2;
            message.message = chunk.substring(message.headerLength + 2, len);
        }
        else
        {
            message.messageLength += (int)len;
            message.message += chunk;
        }

        if (message.messageLength == message.totalMessageLength)
        {
                 parseMasterFreeDs(message.message);
            client->close(true);
        }
    });

    if (!aClient->connect(String(config.sensor_ip).c_str(), 80))
    {
        Serial.println("Connect Fail");
        AsyncClient *client = aClient;
        aClient = NULL;
        delete client;
    }
}

and this is the log:

Connected
Disconnected
Connected
Disconnected
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
Connected
Disconnected
Connected
Disconnected
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL
Connected
Disconnected
Connected
Disconnected
Connected
Disconnected
Connected
Disconnected
Connected
Disconnected
[W][AsyncTCP.cpp:949] _poll(): pcb is NULL

What can I do to avoid this?

Thanks.

zekageri
@zekageri
I get pcb null too every time when a request comes. If you have to get requests in every two sec why dont you do it with websocket? If it is a small packet then the async socket is perfect for this
pablozg
@pablozg

I get pcb null too every time when a request comes. If you have to get requests in every two sec why dont you do it with websocket? If it is a small packet then the async socket is perfect for this

It is a multipurpose request, it depends on the sensor used, one sends a 128 byte json, but another sensor sends a 3882 byte xml.
I am currently using the httpclient library to send the request, but it freezes the entire loop waiting for the response.

Michael
@sparkplug23
It might be worth adding a timeout into your webside of the code. I recently added abortcontroller to my fetching, which has helped a lot. Previously if data was requested but for some reason didn't send, asyncwebrequest would hang, and not free the memory, so when another (or few more) requests came in I eventually overflowed. Added a timeout to cancel the request free's the memory again.
Vahe Arakelyan
@araqel_twitter

@araqel_twitter not enough spare time to write code, sorry. I just know that AJAX and websockets are used for async client->server communication

I have solved the subject. Thanks for attention.

Alexandr Zarubkin
@me21
👍
zekageri
@zekageri
I send sensor requests with websocket. There are no waiting. I just send it if the measure is over, and if there is a client it will get the data. After that i separate the messages on the js side. You can detect if it is a json or an xml in a string or whatever.
pablozg
@pablozg
@zekageri Thanks, but I'm not using JS, I'm using an esp32 to inquiry another esp32 with asyncwebserver and other IoT like wibeee, shelly EM and solar inverters to get the data. Could you post an websocket client example you are using or how to do it with the esp32? Best regards.
zekageri
@zekageri

I have no example for it, maybe you can find it in github on the async lib. But i can copy some code in here.

/** ASYNCRON WEBSOCKET CALLBACK **/
AsyncWebSocketClient * globalClient = NULL;
void onWsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len){
  if(type == WS_EVT_CONNECT){
    Serial.println("Async_WebSocket_Connected");
    globalClient = client;
  } else if(type == WS_EVT_DISCONNECT){
    globalClient = NULL;
    Serial.println("Async_WebSocket_Disconnected");
  }
}

AsyncWebServerRequest *request;
AsyncWebSocket    ws("/test");

void setup(){
ws.onEvent(onWsEvent);
server.addHandler(&ws);
}
And you an send messages like this:
// MSG IS A STRING OR CHAR
if(globalClient != NULL && globalClient->status() == WS_CONNECTED){
    globalClient->text(msg.c_str(),msg.length());
    }
Mael
@Mael61255903_twitter
Hi dear friends ! I'm facing a slight difficulty with my server responses, I would like to know if there is a server status available or something else that could confirm exactly when a response has been fully sent ?
I've read the doc and I couldn't find anything like this. The goal is to wait until a response has been sent before starting a WiFi.scanNetworks() , other wise the scan process delays the response.
zekageri
@zekageri
Do you send a http request from a web to the esp and want a response on the web script? In this case you always have to send a response back, if you don't the request stays open until your esp crashes. :'D

@zekageri
Do you send a http request from a web to the esp and want a response on the web script? In this case you always have to send a response back, if you don't the request stays open until your esp crashes. :'D
For example if you want a script.js from your spiffs you would request it from the web with http request and handle it in the esp like this:

server.on("/script.js", HTTP_GET, [](AsyncWebServerRequest *request) {
    AsyncWebServerResponse* response = request->beginResponse(SPIFFS, "/script.js", "text/javascript");
    response->addHeader("Content-Encoding", "gzip");
    request->send(response);
});

And the response contains the requested script.js.

Or if you want a simple url request that you can handle it like this:

server.on("/Test_URL", HTTP_GET, [](AsyncWebServerRequest *request){
    AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", "Some response for the /Test_URL request.");
    response->addHeader("Access-Control-Allow-Origin","*");
    request->send(response);
});
amgrays
@amgrays
I have a a regular code section that monitors whether a GET or POST is in process and then issues a callback if neither is true.
Mael
@Mael61255903_twitter
Hi,
I probably badly explained my needs. Its on the server side that I would like to know when the response->send() has actually been fully sent. Is there an equivalent of WiFi.status() for the server that I would not be aware of ?
Mael
@Mael61255903_twitter
No one ?
Bert Melis
@bertmelis
You could hack into the lib and use the ack handler.
thbl
@thbl
@me-no-dev could some one please help with me-no-dev/AsyncTCP#83
Kim Burndred
@kburndred
I am using templates but it seems that legitamate use of % causes a problem. Any workarounds?