-
-
Save igrr/1621cf555955cb7fb2de7efdd3be201d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESPAsyncTCP.h> | |
#include <Ticker.h> | |
#include <ESPAsyncWebServer.h> | |
#include <ESP8266WiFi.h> | |
#include <functional> | |
using namespace std; | |
using namespace placeholders; | |
class MyServer : public AsyncWebServer { | |
public: | |
MyServer(int port) : AsyncWebServer(port) { | |
} | |
void begin() { | |
_periodicTrigger.attach(1.0f, &MyServer::s_periodicTask, static_cast<void*>(this)); | |
on("/index.html", std::bind(&MyServer::indexHandler, this, _1)); | |
AsyncWebServer::begin(); | |
} | |
protected: | |
Ticker _periodicTrigger; | |
int value = 0; | |
void indexHandler(AsyncWebServerRequest* request) { | |
String text = "Value is " + value; | |
request->send(200,"text/html",text); | |
} | |
void periodicTask() { | |
Serial.printf("Periodic task. Result = %d\n", value); | |
value++; | |
} | |
static void s_periodicTask(void* arg) { | |
MyServer* self = reinterpret_cast<MyServer*>(arg); | |
self->periodicTask(); | |
} | |
}; | |
MyServer server(80); | |
void additionalHandler(AsyncWebServerRequest* request) { | |
request->send(200, "text/html", "normal handler"); | |
} | |
void setup() | |
{ | |
//Error(active) function "AsyncWebServer::on(const char *uri, ArRequestHandlerFunction onRequest)" (declared at line 372 of ESPAsyncWebServer.h is inaccessible CallbackTest.ino 55 | |
server.on("/other.html", additionalHandler); | |
server.begin(); | |
} | |
void loop() | |
{ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment