Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 18:51
    MichielfromNL edited #969
  • 18:44
    MichielfromNL edited #969
  • 18:43
    MichielfromNL edited #969
  • 15:07
    zekageri commented #932
  • 13:33
    DShabroff commented #965
  • 13:32
    DShabroff commented #965
  • 13:29
    tonydee2377 commented #932
  • 11:58
    MichielfromNL edited #969
  • 11:57
    MichielfromNL edited #969
  • 11:56
    MichielfromNL opened #969
  • 06:03
    zekageri commented #932
  • 06:00
    zekageri commented #932
  • Apr 16 14:58
    stevesch commented #932
  • Apr 16 13:21
    Cutiino commented #968
  • Apr 16 06:28
    zekageri commented #966
  • Apr 16 06:28
    zekageri commented #968
  • Apr 16 01:29
    stevesch commented #932
  • Apr 15 14:42
    Cutiino opened #968
  • Apr 15 09:00
    Pablo2048 commented #965
  • Apr 15 08:49
    DShabroff commented #965
Gonzalo
@gnalbandian
Hi @me-no-dev . I am using ESPAsyncWebServer WebSockets. I am using the sample code provided in github (Async WebSocket Event). When message is received, I set two pointers variables in the , one pointing to the client (AsyncWebSocketClient) that send the message, and the other pointer (uint8_t) to the data itself. This is because I want to deal with the data outside the OnEvent function. Is there anyway in which to protect the received data buffer until read by the processing function? Sometimes it works and I can read the data of the buffer, but most times it seems the buffer gets destroyed or overwritten and I can't process the received message.
sillyfrog
@sillyfrog
@brutzler I looked at this some time ago - if you look at SPIFFSEditor.cpp you'll see that there's preliminary support for directories, but as SPIFFS never truly supported them, the implementation has some issues (now LittleFS does support them). The corresponding edit.htm also does not support them. I did look at fixing it, but didn't have the time to wrap my head around it all and get it implemented as I could work around it.
@gnalbandian I think you'll need to copy the value to memory you control, as it will be free'd as soon as the event is over. (At least that's what I have done in my programs.)
bpoxperts
@bpoxperts
BPOXperts combines Customer Service expertise and business intelligence to catalyze change and deliver results. https://bpoxperts.com/
Cakes and Bakes
@cakesandbakes
Cakes and Bakes offering you the Best Quality of Customized Cakes for your birthday, wedding, and all your special occasions. https://cakesandbakes.com/
csicso
@csicso
Hi, I have a telemetry class in arduino which contains the AsyncWebServer and handle the requests. I need to access the parent class variables in server.on method to send calculated data stored in the class... How is it possible?
zhivko
@zhivko
@me-no-dev me-no-dev/ESPAsyncTCP#77 - Could you check ?
Robert
@Twinsen01_twitter
Is there a workaround to limit the number of requests the library can serve at the same time? I have the classic problem of trying to serve a static multiple file website from spiffs, but on Android Chrome it tries to request around 5 files at the same time and it just hangs on one of the files.
I tried htmlark like suggested above but it fails on css font urls. I really don't mind the "slow" speed of making multiple requests, it's just 1-2 seconds.
It seems like the library will gladly serve and upload however many simultaneous requests it gets even if it will fail
makerMcl
@makerMcl
Hello, I have a challenge with large placeholders, see Issue #954 for it.
I now plan to implement+contribute an extension for a stateful response source aka responding via Stream or beginChunkedResponse. What I do need in addition to that is a callback when response is closed/destruct, as in ~AsyncFileResponse().
@me-no-dev mentioned a request._tempObject once in the past, but I could not found that anymore.
Is there already any solution for such "stateful response handlers"?
makerMcl
@makerMcl
Sorry, I got a itch and couldn't wait for an answer ;-)
A solution has been implemented.
Would you please consider checking pull request #955 and then close issue #954 ?
KhuongTran
@QuangKhuongIoT
I am a newbie, i don’t know how to use AsyncFSBrowser with config filesystem LittleFs, could you please suggest me something to lookaround?
sillyfrog
@sillyfrog
@QuangKhuongIoT My recent project uses either LittleFS (default) or SPIFFS via a #define FFS LittleFS, see here for the code: https://github.com/sillyfrog/PrettyLights2/blob/master/src/main.cpp
The README.md shows how to upload files using curl if you are running the SPIFFSEditor (which this code is obviously, and it works with LittleFS with the right config, despite the name).
KhuongTran
@QuangKhuongIoT
@sillyfrog thanks you for your kindness, i check it now.
Paul Forti
@kustom666

Hey guys, I have the simplest possible server setup with only one handler

server.on("/", HTTP_ANY, [](AsyncWebServerRequest *request) {
    Serial.printf("Socials ANY\n");
    request->send(200);
  });

Sending an OPTIONS request to this doesn't trigger either that handler OR any not found handler I set up. The request just times out

curl -X OPTIONS --verbose --url http://192.169.1.70 just hangs until it times out
I've tried using both the latest version and the master branch
Paul Forti
@kustom666
other verbs like GET, POST, PUT work no problem
Paul Forti
@kustom666
update: using the git main branch of the arduino core solved the issue
Matt
@LocoMatt
What's actuall diffrence between send and send_P?
As I can see it operates around progmem?
bustedbunny
@bustedbunny
sirs. Anyone can take a look at issue?
me-no-dev/ESPAsyncWebServer#962
jethomson
@jethomson
Hello. Is there a way to get the file size before the upload handler is called?
//AsyncCallbackWebHandler& on(const char* uri, WebRequestMethodComposite method, ArRequestHandlerFunction onRequest, ArUploadHandlerFunction onUpload);
web_server.on("/flash_firmware", HTTP_POST,
[](AsyncWebServerRequest *request) {
    Serial.println("in request handler");
    //"update" is the name of the file input <input type='file' name='update'>
    if (request->hasParam("update", true, true)) {
        Serial.print("request handler - filesize: ");
        Serial.println(String(request->getParam("update", true, true)->size()).c_str());
        upload_file_size = request->getParam("update", true, true)->size();
    }
}, 
[](AsyncWebServerRequest *request, const String &filename, size_t index, uint8_t *data, size_t len, bool final) {
    Serial.println("in upload handler");
    //"update" is the name of the file input <input type='file' name='update'>
    if (request->hasParam("update", true, true)) {
        Serial.print("(1) upload handler - filesize: ");
        Serial.println(String(request->getParam("update", true, true)->size()).c_str());
        upload_file_size = request->getParam("update", true, true)->size();
    }
    Serial.print("(2) upload handler - filesize: ");
    Serial.println(upload_file_size);
    //handle_flash_firmware(request, filename, index, data, len, final);
});
That code prints out:
in upload handler
// notice that (1) upload handler - filesize: is never printed
(2) upload handler - filesize: 0
in request handler
request handler - filesize: 8
So the upload handler is called first but the file size is not available when in the upload handler. I need the file size before the upload process starts.
Cellie
@CelliesProjects

@me-no-dev I am trying to use `errorToString'


  aClient->onError([](void * arg, AsyncClient * client, err_t error) {
    ESP_LOGE( TAG, "aSyncClient error %i", error);
    ESP_LOGE( TAG, "aSyncClient error code %s", errorToString(error)));
    aClient = NULL;
    delete client;
  }, NULL);

but get this message:

In file included from /home/cellie/Arduino/hardware/espressif/esp32/cores/esp32/esp32-hal.h:45:0,
                 from /home/cellie/Arduino/hardware/espressif/esp32/cores/esp32/Arduino.h:35,
                 from /dev/shm/build/arduino/sketch/aSync_client.ino.cpp:1:
/home/cellie/Desktop/aSync_client/aSync_client.ino: In lambda function:
aSync_client:53:68: error: 'errorToString' was not declared in this scope
     ESP_LOGE( TAG, "aSyncClient error code %s", errorToString(error)));
For posterity:

  aClient->onError([](void * arg, AsyncClient * client, err_t error) {
    ESP_LOGE( TAG, "aSyncClient error %i", error);
    ESP_LOGE( TAG, "aSyncClient error code %s", client->errorToString(error));
    aClient = NULL;
    delete client;
  }, NULL);
Solved.
jethomson
@jethomson
@BlueAndi That's the approach I used as a workaround, but it required POSTing with javascript. Having the file size available in the upload handler would make things much the webpage code much simpler.
Mike Dunston
@atanisoft
File uploads are typically a POST, there is a header included by the client with the part size. The callback from the webserver provides a chunk size only. But you should be able to grab the segment header or at worst case the overall Content-Length header (it will be larger than the actual file upload though)
jethomson
@jethomson
I see now that size() (_itemSize) comes from counting up the number of bytes uploaded, so it isn't available until after the upload. The original code I used calls contentLength() which works fine for uploading firmware because firmware size + a little extra from the contentLength() "boundary=----..." header and footer is still less than the space available. The problem is when I try to upload a littlefs.bin that is exactly 1MB and there is 1MB of space available using contentLength() makes it look like the file is too big for the space available.
jethomson
@jethomson
I see if I add an input with the size of the file to my html form before the file input that the file size input gets read in before the upload handler is called, so some potential there to explore. I'll post an update.
jethomson
@jethomson
Yes, this solution works well! It works much better for me than using javascript to POST with a custom header. Uploading is quicker and more reliable.
jethomson
@jethomson
Here are some snippets to help out anyone else that had this problem:

<form id='flash' method='POST' action='/flash_firmware' enctype='multipart/form-data'>
<!--need to upload filesize first because Content-Length [request->contentLength()] isn't the actual file size-->
<input id='filesize' name="filesize" value="0" style="display:none">
<input id='file' type='file' name='update'>
<p></p>
<input id='flash_btn' type='submit' value='Flash'>
</form>

<script>
document.querySelector('form').addEventListener('submit', (e) => {
document.getElementById('filesize').value = document.getElementById('file').files[0].size;
});
</script>

size_t filesize = 0;
if (request->hasParam("filesize", true)) {
// because contentLength() doesn't work for spiffs or littlefs had to use a separate form input to upload actual filesize.
filesize = request->getParam("filesize", true)->value().toInt();
}
else {
// this doesn't work for spiffs or littlefs because contentLength() includes count of bytes in bin file plus header and footer
filesize = request->contentLength();
}
Turbotronics
@Turbotronics
Does anyone still experience the websockets random disconnect issues? I am at the end of a 3 year dev cycle and have not been able to contain it. Only other issue I had was the 5-file limit on filerequest which was solved by using JS function that would only request the next file once it has actually been loaded. Not much difference in download speed. For static images local storage is a great workaround.
Gonzalo
@gnalbandian
Hi @Turbotronics. I have faced the two same issues as you. WebSocket disconnection is an ongoing issues with ESPAsyncWebServer and its underlying use os ESPAsyncTCP. There are many forks that seems to fix this. Haven't tryed anyone yet. It's a pity the main lbrary is stalled and not willing to accept pull requests. The second issues, the 5-file limit, I solve it creating only one huge html file with all the content embedded (html, css, js)
Turbotronics
@Turbotronics
Hi Gonzalo, thanx for the feedback. Do you have links to the other forks? My i/f is a controller dashboard than must always be responsive to user input. I am considering using streams to replace the socket since so far I have had no issues transfering data that way. I had a function calling a sequence of strings to tx to client. It was painfully slow since without long intervals it would break. Replacing this with an XMLHttpRequest made is almost instant.
Michael Heinrich
@pinki

Hi!
I want to write a file upload handler class.
My current class is

class UpdateMasterRequestHandler : public AsyncWebHandler {
public:
    UpdateMasterRequestHandler(/* args */) { }
    virtual ~UpdateMasterRequestHandler() { }

    bool canHandle(AsyncWebServerRequest *request);
    void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final);
};

canHandle returns true, but handleUpload never gets called.
What am I doing wrong?

bool UpdateMasterRequestHandler::canHandle(AsyncWebServerRequest *request) {
    bool forMe = request->url() == "/api/UpdateMaster"
              && request->method() == HTTP_POST
              && request->multipart();
    if (forMe) logDebugln("UpdateMasterRequestHandler!");

    return forMe;
}

void UpdateMasterRequestHandler::handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) {
    if (index == 0) {
        logDebug("UploadStart: ");
        logDebugln(filename);

        request->_tempFile = SPIFFS.open("master.hex", "w");
    }

    if (len > 0) {
        request->_tempFile.write(data, len);
    }

    if (final) {
        logDebug("UploadEnd: ");
        logDebugln(filename);

        request->_tempFile.close();

        request->send(200, MIME_TYPE_PLAIN_TEXT, "Upload complete!");
    }
}
HTML:
<form id="masterUpdateForm" action="/api/UpdateMaster" method="POST" enctype="multipart/form-data">
    Firmware: <input type="file" name="file" accept="*.hex">
    <button type="submit">Update</button>
</form>
Michael Heinrich
@pinki
I also tried this:
class UpdateMasterRequestHandler : public AsyncWebHandler {
public:
    UpdateMasterRequestHandler(/* args */) { }
    virtual ~UpdateMasterRequestHandler() { }

    virtual bool canHandle(AsyncWebServerRequest *request) override final;
    virtual void handleRequest(AsyncWebServerRequest *request) override final;
    virtual void handleUpload(AsyncWebServerRequest *request, const String& filename, size_t index, uint8_t *data, size_t len, bool final) override final;
};
Michael Heinrich
@pinki
I found the solution. I had to override isRequestHandlerTrivial as well and make it return false.
BinaryFour
@BlNARYFOUR
Hi, is there a complimentary ESP8266 WebSocket library for ws clients? I used the library for Wemos D1 Mini as websocket server, which works great! But I want to connect to this websocket server using a second Wemos D1 Mini. Can I do this using the same library? Or is there a complimentary library?
Cellie
@CelliesProjects
@me-no-dev I am working on a project that uses AsyncTCP for networking.
Is there a way to disable the WDT on the Async task?
Paul Andrews
@judge2005
I am curious about how async TCP works on the ESP8266. In particular, do I need to be careful about concurrency issues in handlers?
Should maybe have tagged that with @me-no-dev :-)