Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Jan 20 15:20
    zekageri commented #1110
  • Jan 19 22:18
    pedros89 commented #1022
  • Jan 19 12:36
    stale[bot] unlabeled #1022
  • Jan 19 12:36
    stale[bot] commented #1022
  • Jan 19 12:35
    perotom commented #1022
  • Jan 18 21:04
    udiFi commented #975
  • Jan 18 14:22
    jmattioni opened #1112
  • Jan 18 11:22
    openedhardware commented #435
  • Jan 17 19:52
    alixti commented #1087
  • Jan 16 18:07
    marcpascualsanchez edited #1111
  • Jan 16 18:03
    marcpascualsanchez edited #1111
  • Jan 16 17:52
    marcpascualsanchez edited #1111
  • Jan 15 21:32
    marcpascualsanchez opened #1111
  • Jan 13 14:21
    PabloASua opened #1110
  • Jan 13 14:04
    weoiss1998 commented #1085
  • Jan 13 13:22
    stale[bot] unlabeled #979
  • Jan 13 13:22
    stale[bot] commented #979
  • Jan 13 13:22
    MoJo2600 commented #979
  • Jan 13 11:10
    videojedi commented #936
  • Jan 13 11:08
    videojedi commented #936
Sloata George
@GeorgeFlorian

Are there any examples of dynamic web pages using ESPAsyncWebServer ?
I would like to GET and POST data without having to reload the page every time.

Right now each request ends with redirect which reloads the page:

  server.on("/settings", HTTP_POST, [](AsyncWebServerRequest *request)
            {
              if (request->hasArg("save_output"))
              {
                // do something with the received data
                request->redirect("/settings");
              }
              else
              {
                request->redirect("/settings");
              }
            });

But request->redirect("/settings"); reloads the page.
Can I change this behavior ?

Anthony
@ARprogramer_twitter
Hi I am new to programing and Arduino can you please anyone help me out I'm stuck on this error code :
C:\Users----\Documents\Arduino\libraries\ESPAsyncTCP-master\src\SyncClient.cpp:25:24: fatal error: interrupts.h: No such file or directory
compilation terminated.
exit status 1
Error compiling for board ESP32 Dev Module.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
I downloaded * ArduinoJson (Request Pool Version 2.6)
Anthony
@ARprogramer_twitter
What did I not include or configure?
Anthony
@ARprogramer_twitter
I'm using a ESP32s wroom board 38pin. Sorry if I seem to be spamming I'm just trying to include the information needed to complete compilation and understand the libraries for the sketch to verify so I can then upload.
Mick Percy
@DeeEmm

@GeorgeFlorian you need to exchange data between server and client using websockets. This means you need to create your own protocols for exchanging data and updating the DOM.

I'm currently doing this on a project that I am working on... https://github.com/DeeEmm/DIY-Flow-Bench/tree/ESP32

The way that I have done this is that both the browser and ESP32 have websocket listen events. I'm exchanging JSON data and adding a header value to each JSON object before transmission. The header acts as a simple protocol to let the receiving side know what to do. When websocket data is received the JSON 'header' value is decoded and the relevant action taken. Some transmissions only have a header value, others have the header value with additional data. This data exchange is both bidirectional and asynchronous so falls outside of the main loop.

On the browser side you can update the DOM using simple document.getElementById statements

Check out the index.html / javascript.js files for the client implementation and the Webserver::ProcessWebSocketMessage method in Webserver.cpp for the ESP side.

For an example of the JSON data I am using take a look in data/config.json

Using JSON makes the data exchange nice and easy on both sides as there are already tools available for both the browser (native javascript) and ESP32 (ArduinoJson library) to manage JSON data objects. It also makes storing configuration data in SPIFFS nice and easy too.

There is one caveat to this - file uploads - Traditionally they are handled via POST vars and require a navigation event (file / form submit) to transmit them. HTML5 does have a transport method that does not require this but I have not played with it (yet) so cannot comment. However it appears that this method is not backwards compatible in older browsers.

/DM

Mick Percy
@DeeEmm
@GeorgeFlorian In your example you show 'settings'. The way that I have dealt with this is to use a modal dialog that is hidden. This is unhidden using simple javascript trigger by a user on-click event. In fact there are several such dialogs / tabs that are all within the one index.html page and are hidden / unhidden accordingly. This gives the impression of navigation without any form of redirect or page reload.
Apoorva Singh
@meticulouscraftman:matrix.org
[m]
Hello everyone,
Is there any example that shows how to setup a loopback connection to a server built using ESPAsyncWebServer.
I tried using the IP address of the device using the ESP8266's WiFiClient library. But for some reason it's unable to connect to the server.
My goal is to run a server as well as have a client connection on the same ESP8266 that forwards HTTP requests from a different source to ESPAsyncWebServer. If you guys can point me towards some resources, it would be very helpful. Thank you!
Sloata George
@GeorgeFlorian

Hello.

I encountered this project: https://github.com/DroneBridge/ESP32 and I saw that the web-page works flawlessly and the information on page change without refreshing the page even on submit.

I am using this web-server for my projects and each time I submit data (POST) to the server I redirect to the same page, meaning that I reload the page.

This is a GET handler:

    server.on("/home", HTTP_GET, [](AsyncWebServerRequest *request)
              { request->send(SPIFFS, "/index.html", "text/html", false, processor); });

This is a POST handler:

  server.on("/home", HTTP_POST, [](AsyncWebServerRequest *request)
            {
              if (request->hasArg("send_data_when_submit_btn_pressed"))
              {
                int params = request->params();
                for (int i = 0; i < params - 1; i++)
                {
                  AsyncWebParameter *p = request->getParam(i);
                  if (p->isPost() && p->value().length() > 0 && p->value() != "#000000")
                  {
                    if (p->name() == "brightness")
                      Brightness = p->value();
                  }
                }
                request->redirect("/home");
              }
              else if (request->hasArg("toggle_btn"))
              {
                outputFlag = !outputFlag;
                String str = outputFlag ? "On" : "Off";
                request->redirect("/home");
              }
              else
              {
                request->redirect("/home");
              }
            }); // server.on("/home", HTTP_POST, [](AsyncWebServerRequest * request)

As you can see, for each action I am required to use request->redirect("/home"); which reloads the page when redirecting.

Also, I am currently using AJAX calls to refresh or change data on the page without reloading the page:

var text_box = document.querySelector('.text_box');

if (text_box != null || rs1 != null || rs2 != null) {
    function refresh() {
        setTimeout(function () {
            if ($('.text_box').length) $('.text_box').load('events_placeholder.html');
            refresh();
        }, 1000);
    }

    $(document).ready(function () {
        if ($('.text_box').length) $('.text_box').load('events_placeholder.html');
        refresh();
    });
}

This makes a call to the events_placeholder.html each second and it seems resource consuming.
Is there a better way of doing this ?

Is it possible to implement a framework like VueJS for example on this web-server ?

Louis Lewis
@louislewis2

Hi everyone,

I have looked at the documentation regarding handling post requests, but I cannot seem to find the answers I am looking for.
I am porting some code which was using the plain WebServer implementation. With that implementation I have multiple post requests being used like this

this->webServer->on("/api/configuration/wifi", HTTP_POST, [this]()
{
    String data = this->webServer->arg("plain");

    DynamicJsonDocument doc(500);
    DeserializationError error = deserializeJson(doc, data);

        // rest of code omitted.......
}

this->webServer->on("/api/configuration/timer", HTTP_POST, [this]()
{
    String data = this->webServer->arg("plain");

    DynamicJsonDocument doc(500);
    DeserializationError error = deserializeJson(doc, data);

        // rest of code omitted.......
}

I was reading about the onRequestBody method, which I tried using.

this->webServer.onRequestBody([this](AsyncWebServerRequest *request, uint8_t *data, size_t len, size_t index, size_t total)
{
  if (request->url() == "/api/configuration/wifi")
  {
      this->HandleWifiConfig(request, data);
  }
});

With the above, In the HandleWifiConfig method does indeed get called, it does return a response, using

 request->send(200, "application/json", "testing");

However the onNotFound handler still gets called.

Am I still meant to register a handler using "webServer.on(......"?
If so, what would the signature look like?

On the client side, I am doing a normal http post request, with the body being set to json.
I am not too keen on using the Json handler as documented, I would rather stick to my manual parsing for the moment, its been working for a year.

Thanks

Louis Lewis
@louislewis2
Louis Lewis
@louislewis2

Good evening,

I ran into an issue, hopefully someone can assist.
I have two endpoints

    this->webServer.on("/api/configuration/wifi", HTTP_GET, [this](AsyncWebServerRequest *request)
                       {
                           AsyncWebServerResponse *response = request->beginResponse(200, "application/json", wifiManager.GetConfigurationAsString());
                           response->addHeader("Access-Control-Allow-Origin", "*");

                           request->send(response);
                       });

    this->webServer.on("/api/configuration/wifi/status", HTTP_GET, [this](AsyncWebServerRequest *request)
                       {
                           WiFiStatus wifiStatus = wifiManager.GetStatus();

                           AsyncWebServerResponse *response = request->beginResponse(200, "application/json", wifiStatus.ToString());
                           response->addHeader("Access-Control-Allow-Origin", "*");

                           request->send(response);
                       });

I am calling this endpoint http://192.168.4.1/api/configuration/wifi/status
Which should map to the second endpoint above, however it is the first one that gets executed.

Am I doing something wrong?

Mike Dunston
@atanisoft
swap the order of them
put the /api/configuration/wifi/status one first
Louis Lewis
@louislewis2
Awesome, thanks once again Mike.
Worked like a charm
Mike Dunston
@atanisoft
np
Brad Nelson
@bnelson796:matrix.org
[m]
What is the easiest way to determine if a client has connected to Espasyncwebserver?
Sloata George
@GeorgeFlorian

How can I serve the css and js files without an actual path ? Let's say we have the following handler:

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

If the user goes to /script.js he will have access to the file and this seems like a security issue.

1 reply
vijay seshu ravankol
@VijaySeshuR

I am using ESPAsyncWebServer for a server application. Will receive WiFi credentials Through POST request. Now I want to send response to client only after WiFi is connected. if i try to connect to wifi within

server.on(
"/abc",
HTTP_POST,
{},
NULL,

{
ConnectWiFI();
if(wificonnected())
{
request->send(200);
}
else
{
request->send(400);
}
})

Im getting WGT error if credentials are wrong. How can i use request->send out of this block? or any other suggestions?
Thanks in advance.

BErik
@LearnDude
Hi Everyone, I'm trying to figure out when to use AsyncWebServerRequest->send vs. when to use AsyncWebServerRequest->send_P . What's the difference between the two? I just want to serve simple HTML.
2 replies
Tomas Hübner
@Titantompa
Hey everyone, I'm woking on a clock using pinball score reels based on an ESP32, and I'm storing some data in an I2C eeprom that happened to be on the same module as the DS1307 used to keep time when power is off.
I've added a page with a simple form to change the config. I did have major issues writing data to the eeprom in a callback from the ESPAsyncWebServer - as it turned out there were some yield()s in the lib I use for eeprom access. At least I think that was what caused the problems.
However, being well aware that assumption is the mother of all fuckups, I just wanted to check if anyone knows if there is anything in ESPAsyncWebServer that actually would interfere with the TwoWire implementation?
2 replies
bigtiger0905
@bigtiger0905

hi everyone, i have random wdt.
E (285848) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (285848) task_wdt: - IDLE0 (CPU 0)
E (285848) task_wdt: Tasks currently running:
E (285848) task_wdt: CPU 0: Task0
E (285848) task_wdt: CPU 1: IDLE1
E (285848) task_wdt: Aborting.
abort() was called at PC 0x40174258 on core 0

ELF file SHA256: 0000000000000000

Backtrace: 0x400887e8:0x3ffbfa70 0x40088a65:0x3ffbfa90 0x40174258:0x3ffbfab0 0x40086f25:0x3ffbfad0 0x4000bfed:0x3ffdb970 0x4008abe9:0x3ffdb980 0x400894e1:0x3ffdb9a0 0x40166866:0x3ffdb9e0 0x4015633c:0x3ffdba00 0x400d8981:0x3ffdba20 0x400d89e6:0x3ffdba50 0x400d8a55:0x3ffdba70 0x400d8e96:0x3ffdba90 0x4018afb6:0x3ffdbac0 0x400ea915:0x3ffdbaf0 0x400ea9ad:0x3ffdbb10 0x400de266:0x3ffdbb30 0x400dc9e9:0x3ffdbcf0 0x400d82e2:0x3ffdbd40 0x400d3b00:0x3ffdbd60 0x40089a76:0x3ffdbd80

Rebooting...
ets Jun 8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,l
2021-10-26 12:15:37.713
en:10124
load:0x40080400,len:5828
entry 0x400806a8

Decoding stack results
0x400887e8: invoke_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c line 156
0x40088a65: abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/panic.c line 171
0x40174258: task_wdt_isr at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp32/task_wdt.c line 174
0x4008abe9: vTaskExitCritical at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/tasks.c line 4274
0x400894e1: xQueueGenericSend at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/queue.c line 828
0x40166866: sys_mutex_unlock at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/port/esp32/freertos/sys_arch.c line 93
0x4015633c: lwip_ioctl_r at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/lwip/lwip/src/api/sockets.c line 3489
0x400d8981: WiFiClientRxBuffer::r_available() at C:.platformio\packages\framework-arduinoespressif32\libraries\WiFi\src\WiFiClient.cpp line 49
0x400d89e6: WiFiClientRxBuffer::fillBuffer() at C:.platformio\packages\framework-arduinoespressif32\libraries\WiFi\src\WiFiClient.cpp line 71
0x400d8a55: WiFiClientRxBuffer::read(unsigned char, unsigned int) at C:.platformio\packages\framework-arduinoespressif32\libraries\WiFi\src\WiFiClient.cpp line 107
0x400d8e96: WiFiClient::read(unsigned char
, unsigned int) at C:.platformio\packages\framework-arduinoespressif32\libraries\WiFi\src\WiFiClient.cpp line 437
0x4018afb6: WiFiClient::read() at C:.platformio\packages\framework-arduinoespressif32\libraries\WiFi\src\WiFiClient.cpp line 345
0x400ea915: Stream::timedRead() at C:.platformio\packages\framework-arduinoespressif32\cores\esp32\Stream.cpp line 36
0x400ea9ad: Stream::readStringUntil(char) at C:.platformio\packages\framework-arduinoespressif32\cores\esp32\Stream.cpp line 330
0x400de266: WebServer::_parseRequest(WiFiClient&) at C:.platformio\packages\framework-arduinoespressif32\libraries\WebServer\src\Parsing.cpp line 78
0x400dc9e9: WebServer::handleClient() at C:.platformio\packages\framework-arduinoespressif32\libraries\WebServer\src\WebServer.cpp line 310
0x400d82e2: webserver_loop() at src\webserver_pro.cpp line 312
0x400d3b00: Task0code(void*) at src\main.cpp line 41
0x40089a76: vPortTaskWrapper at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/freertos/port.c line 143

but don't know how to fix.

it happens randomly. 1 day or several days.
dm5xx
@dm5xx
Hi all. I am reading an value continously in my code and writing it in a global varibal. in my server.on callback i am reading this value and returning it to the clients browser. for sure its crashing when i write it the same time.
Q1: how is the best way to avoid this (i am using a locked-variable at the moment).
Q2: since its async somehow, is there task scheduling and running on different cores@esp32 involved? Best way to exchange "data"/share aviables between "global code" and webserver(callbacks?
Hope im not mixing things too much - and sri for some rookie questening stuff :) Tnx for your support. M.
GitHub King
@HubKing

Can it handle multipart form? I browsed the readme, but the only thing I could find was multipart() that returns true/false. I want to know whether it can read values from a multipart POST. I confirmed that my POST code works correctly by posting it to https://httpbin.org/post; it returned

{
    "args": {}, 
    "data": "", 
    "files": {}, 
    "form": {
        "cat": "\u0001\u0002\u0000\u0003\u0004", 
        "dog": "hello"
    }, 
    "headers": {
        "Content-Length": "265", 
        "Content-Type": "multipart/form-data; boundary=\"8a9f2dc0-11a8-451a-9d5e-376624de7af7\"", 
        "Host": "httpbin.org",  .....

So, I want to get that "dog" and "cat" in my ESP. But when I listed all arguments using the readme code:

          //List all parameters (Compatibility)
          int args = request->args();
          for (int i = 0; i < args; i++)
          {
            Serial.printf("ARG[%s]: %s\n", request->argName(i).c_str(), request->arg(i).c_str());
          }

what I got was:

    ARG[o]: 
    ARG[a]: ␁␂

So, how can I get the string "hello" for the "dog" argument, and { 0x01, 0x02, 0x00, 0x03, 0x04 } for the "cat" argument? Is it supported? Any example?

5 replies
Also, it does not seem a good idea to use this chat site where everyone's posts are mixed together for "help and support" for the library. Github provides "Discussions" (for example: https://github.com/zadam/trilium/discussions ) which is a LOT better for this purpose, in my opinion. Why not use that instead?
Stephan H. Wissel
@Stwissel

How can I alter content based on a GET requests accept header?
I have a piece of code that looks like this:

server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
    request->send(SPIFFS, "/index.html", String(), false);
  });

which works as designed. However I need to send back different data, depending on the Accept header. Something like this:

server.on("/", HTTP_GET, [](AsyncWebServerRequest * request) {
  if (request->contentType() == "application/json") {
         request->send(200, "text/json", String(publishData));
    } else {
    request->send(SPIFFS, "/index.html", String(), false);
  }});

Doesn't seem to work. What do I miss?

Open Source Hardware
@openedhardware
Hi!
Does anyone have similar issue with this? me-no-dev/ESPAsyncWebServer#435
I am running AP on my ESP32 and webserver from SPIFFS. I can connect to my webserver from my laptop(using wifi dongle), but cannot connect from my mobile phone.
Any idea to fix this?
Artonworks TM
@artonworkstm_gitlab

Hi!
I just couldn't find any working examples for TLS so I made an example sketch for TLS WebServer using this library.
Check it out here: https://gitlab.com/artonworkstm/asyncwebservertls

Also want to fasten up a bit the request process by caching sessions so there is no need to redo the whole handshake at every request.
Do you guys know how may I achieve that?
I found it in the ESP8266WiFi library that you can use there (tho I couldn't make it work).
The Session class is here at line 139: https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/BearSSLHelpers.h

1 reply
chrgweber
@chrgweber
grafik.png
Hi!
I would like to serve following files as gzipped with the severStatic-method. Is this possible?
In the folder "fs" I have placed "all.min.css" and fonts from fontawesome. Do these files also have to be compressed in the folders?
My websever works fine most of the time. But rarely it crashes when an new client is involved. I use SPIFFS (data-directory)
for the files.
Cellie
@CelliesProjects
@chrgweber If you want to serve them gzipped then yes, they have to be gzipped. Also set the Content-Encoding: gzip header.
And Content-Type: application/javascript for jQuery.min
Diego Bonilla
@dieghobonilla
I have had no luck finding a websocket example using ESP32 as client, all the examples I found are with a web/browser based client, do you have any examples of creating a basic esp32 websocket client and server? thank you
István Horváth
@armogur_gitlab
@Stwissel
if (request->contentType().equals("application/json")) {

}
István Horváth
@armogur_gitlab
@openedhardware Are you trying with mDNS? Because it won't work on mobile browsers, you should use IP address.
Rocky
@softwarecrash
Hello, can anyone give me a hint about a little problem, i have splitet html code in progmem chars, and would send it, my way dont work, what is the right?
    server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
              {
                request->send_P(200, "text/html", HTMLhead);
                request->send_P(200, "text/html", HTMLmain);
                request->send_P(200, "text/html", HTMLfoot);
              });
István Horváth
@armogur_gitlab
@softwarecrash Is this sends at least one part? like the HTMLhead? if so I would concatenate the three parts into one and send it that way.
Rocky
@softwarecrash
@armogur_gitlab yes, one part. its a website splittet in head, main contenct (or other content) and foot, head and foot i have seperated to reuse on other pages. the head etc is - "const char HTMLhead[] PROGMEM" type. i dont find a way to concate it without use a lot of memory
István Horváth
@armogur_gitlab
with size_t index as input parameter you can figure out where is the chunked response in the processing, though I not used this method, but looks like it will solve your problem
Rocky
@softwarecrash
@armogur_gitlab thanks, but have you another bigger sampele? i dont understand this code fragment in your link. sorry im not the pro in this things
Rocky
@softwarecrash
@armogur_gitlab can it be so simple? ti have found the print function, and testet, yeah it works, but is it right? looks too simple
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
{
AsyncResponseStream *response = request->beginResponseStream("text/html");
response->printf_P(HTMLhead);
response->printf_P(HTMLMain);
response->printf_P(HTMLfoot);
request->send(response);
});
Rocky
@softwarecrash
ok not so simple.... the processor doenst work, i cant replace things with vars
Rocky
@softwarecrash
printf_P(HTMLMain, processor); dont work in this scenario. any other practicable way to send variables with the request to prefill a dataform?
gecoool
@gecoool
Hello me-no-dev. I am stuck with ESPAsyncTCP ".pio\libdeps\esp12e\ESPAsyncTCP@src-4b2fa33d3d75d4541c5b044be255a09c\src/tcp_axtls.h:44:10: fatal error: include/ssl.h: No such file or directory". I made some researches but without luck. I am trying to make an SSL call to google sheet, but without success. Any pointers / ideas would be much appreciated, as this is a show stopper for my project. Thx !