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?
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
Content-Type: application/javascript
for jQuery.min
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);
});
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);
});
Hi all. Fairly new and very sorry if answered as I've looked but I'm trying to use AsyncWebServer with SdFat and 128 GB exFAT SDHC. I'm having issues with the following lines in my code since I'm not using SD.h
request->send(SD, "/index.html", "text/html");
});
server.serveStatic("/", SD, "/");
I've tried changing SD
to sd
, and file
objects without success. Also tried FS
and fs
with no luck. I'm fairly new and jsut not sure what filesystem to send from SdFat for request->send
hi all
I made a couple of header file for different prepherals + header file for my asyncserver & asyncwebsocket
my_wifi.h
AsyncWebServer server(80);
AsyncWebSocket WS("/ws");
in other header file I have sensor to measure sumeting and send through websocket
my_sensor.h
WS.textAll(my_data);
but it can not see my WS instance error: 'WS' was not declared in this scope
does anyone know how can I pass my WS instance to other header files
Hi guys, i still have a problem - no idea what to do, heres again my question: I am reading an value continously in my main/loop-code and writing it in a global variabal. in my server.on callback/handler function 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.
why not with websocket?
WS.text(WSclinet,data);
however after a while _messageQueue.length()
exceeded of maximum size and throw ERROR: Too many messages queued
, does anyone know how to solve it
clearQ
after each transmitting void AsyncWebSocket::clearQ(uint32_t id){
AsyncWebSocketClient * c = client(id);
if(c)
c->QueuFree();
}
.......
void AsyncWebSocketClient::QueuFree(){
_messageQueue.free();
}
any solutions for using ESP32-C3 Stamp with ESPAsyncWebServer and AsyncTCP.h successfully? getting compile errors on arduino ide 1.8.16 with installed esp32 arduino boardmanager version >= 2.0.0....
C:\Users\thoma\Documents\Arduino\libraries\ESPAsyncWebServer-master\src\AsyncWebSocket.cpp: In member function 'IPAddress AsyncWebSocketClient::remoteIP()':
C:\Users\thoma\Documents\Arduino\libraries\ESPAsyncWebServer-master\src\AsyncWebSocket.cpp:843:28: error: call of overloaded 'IPAddress(unsigned int)' is ambiguous
return IPAddress(0U);
^
In file included from C:\Users\thoma\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/Arduino.h:163,
from C:\Users\thoma\Documents\Arduino\libraries\ESPAsyncWebServer-master\src\AsyncWebSocket.cpp:21:
C:\Users\thoma\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/IPAddress.h:51:5: note: candidate: 'IPAddress::IPAddress(const uint8_t)'
IPAddress(const uint8_t address);
^~~
C:\Users\thoma\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/IPAddress.h:50:5: note: candidate: 'IPAddress::IPAddress(uint32_t)'
IPAddress(uint32_t address);
^~~
C:\Users\thoma\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.0\cores\esp32/IPAddress.h:29:7: note: candidate: 'constexpr IPAddress::IPAddress(const IPAddress&)'
class IPAddress: public Printable
^~~~~
exit status 1