mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2025-08-03 12:44:45 +02:00
Added test case
This commit is contained in:
108
examples/Issue85/Issue85.ino
Normal file
108
examples/Issue85/Issue85.ino
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
#include <Arduino.h>
|
||||||
|
#ifdef ESP8266
|
||||||
|
#include <ESP8266WiFi.h>
|
||||||
|
#endif
|
||||||
|
#ifdef ESP32
|
||||||
|
#include <WiFi.h>
|
||||||
|
#endif
|
||||||
|
#include <ESPAsyncWebServer.h>
|
||||||
|
|
||||||
|
void connect_wifi() {
|
||||||
|
WiFi.mode(WIFI_AP);
|
||||||
|
WiFi.softAP("esp-captive");
|
||||||
|
|
||||||
|
// Serial.print("Connecting");
|
||||||
|
// while (WiFi.status() != WL_CONNECTED) {
|
||||||
|
// delay(500);
|
||||||
|
// Serial.print(".");
|
||||||
|
// }
|
||||||
|
// Serial.println();
|
||||||
|
|
||||||
|
// Serial.print("Connected, IP address: ");
|
||||||
|
// Serial.println(WiFi.localIP());
|
||||||
|
}
|
||||||
|
|
||||||
|
void notFound(AsyncWebServerRequest* request) {
|
||||||
|
request->send(404, "text/plain", "Not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
AsyncWebServer server(80);
|
||||||
|
AsyncWebSocket ws("/ws");
|
||||||
|
|
||||||
|
// initial stack
|
||||||
|
char* stack_start;
|
||||||
|
|
||||||
|
void printStackSize() {
|
||||||
|
char stack;
|
||||||
|
Serial.print(F("stack size "));
|
||||||
|
Serial.print(stack_start - &stack);
|
||||||
|
Serial.print(F(" | Heap free:"));
|
||||||
|
Serial.print(ESP.getFreeHeap());
|
||||||
|
#ifdef ESP8266
|
||||||
|
Serial.print(F(" frag:"));
|
||||||
|
Serial.print(ESP.getHeapFragmentation());
|
||||||
|
Serial.print(F(" maxFreeBlock:"));
|
||||||
|
Serial.print(ESP.getMaxFreeBlockSize());
|
||||||
|
#endif
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void onWsEventEmpty(AsyncWebSocket* server, AsyncWebSocketClient* client, AwsEventType type, void* arg, uint8_t* data, size_t len) {
|
||||||
|
printStackSize();
|
||||||
|
// Just answer
|
||||||
|
client->text("PONGTEST");
|
||||||
|
}
|
||||||
|
|
||||||
|
void serve_upload(AsyncWebServerRequest* request, const String& filename, size_t index, uint8_t* data, size_t len, bool final) {
|
||||||
|
Serial.print("> onUpload ");
|
||||||
|
Serial.print("index: ");
|
||||||
|
Serial.print(index);
|
||||||
|
Serial.print(" len:");
|
||||||
|
Serial.print(len);
|
||||||
|
Serial.print(" final:");
|
||||||
|
Serial.print(final);
|
||||||
|
Serial.println();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
char stack;
|
||||||
|
stack_start = &stack;
|
||||||
|
|
||||||
|
Serial.begin(115200);
|
||||||
|
Serial.println("\n\n\nStart");
|
||||||
|
Serial.printf("stack_start: %p\n", stack_start);
|
||||||
|
|
||||||
|
connect_wifi();
|
||||||
|
|
||||||
|
server.onNotFound(notFound);
|
||||||
|
|
||||||
|
ws.onEvent(onWsEventEmpty);
|
||||||
|
server.addHandler(&ws);
|
||||||
|
|
||||||
|
server.on("/upload", HTTP_POST, [](AsyncWebServerRequest* request) { request->send(200); }, serve_upload);
|
||||||
|
|
||||||
|
server.begin();
|
||||||
|
Serial.println("Server started");
|
||||||
|
}
|
||||||
|
|
||||||
|
String msg = "";
|
||||||
|
uint32_t count = 0;
|
||||||
|
void loop() {
|
||||||
|
|
||||||
|
ws.cleanupClients();
|
||||||
|
|
||||||
|
count += 1;
|
||||||
|
|
||||||
|
// Concatenate some string, and clear it after some time
|
||||||
|
static unsigned long millis_string = millis();
|
||||||
|
if (millis() - millis_string > 1) {
|
||||||
|
millis_string += 100;
|
||||||
|
if (count % 100 == 0) {
|
||||||
|
// printStackSize();
|
||||||
|
// Serial.print(msg);
|
||||||
|
msg = String();
|
||||||
|
} else {
|
||||||
|
msg += 'T';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -2,9 +2,10 @@
|
|||||||
default_envs = arduino-2, arduino-3, arduino-310rc1, esp8266, raspberrypi
|
default_envs = arduino-2, arduino-3, arduino-310rc1, esp8266, raspberrypi
|
||||||
lib_dir = .
|
lib_dir = .
|
||||||
; src_dir = examples/CaptivePortal
|
; src_dir = examples/CaptivePortal
|
||||||
src_dir = examples/SimpleServer
|
; src_dir = examples/SimpleServer
|
||||||
; src_dir = examples/StreamFiles
|
; src_dir = examples/StreamFiles
|
||||||
; src_dir = examples/Filters
|
; src_dir = examples/Filters
|
||||||
|
src_dir = examples/Issue85
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
Reference in New Issue
Block a user