Code Monkey home page Code Monkey logo

Comments (4)

ssieb avatar ssieb commented on July 21, 2024

The AsyncWebServerRequest is available as request in a lambda. See https://github.com/me-no-dev/ESPAsyncWebServer#request-variables for details.

from esphome_components.

brendann993 avatar brendann993 commented on July 21, 2024

Thanks that gets me on the right track. Any idea why they below seems to crash the esp? Basically the server response is empty, the log shows "Got to end of req" but the ESP then drops the connection for a few seconds then reconnects.
Ive been able to access the AsyncWebServerRequest request fine in the function but as soon as I try the stream.print I get that issue. Using stream.print in the lambda itself in yaml also appears to work fine. I have the function in the .h file though as I want to re-use some existing logic.
in device.yaml

- path: /setConfigItem
    on_request:
      - lambda: |-
          gotWebReq(request, stream);
          ESP_LOGD("web_req", "Got to end of req");

in includedFile.h

void gotWebReq(AsyncWebServerRequest request, AsyncResponseStream stream)
{
    stream.print("{\"success\": true}");
    return;
}

from esphome_components.

brendann993 avatar brendann993 commented on July 21, 2024

By updating the includedFile.h to use refs with & instead it works. My lack of C++ knowledge doesn't help me understand why.

void gotWebReq(AsyncWebServerRequest &request, AsyncResponseStream &stream)
{
    stream.print("{\"success\": true}");
    return;
}

from esphome_components.

brendann993 avatar brendann993 commented on July 21, 2024

Works perfectly as mentioned

from esphome_components.

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.