Skip to content

Instantly share code, notes, and snippets.

@igrr

igrr/fixed.ino Secret

Created August 17, 2016 00:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igrr/1621cf555955cb7fb2de7efdd3be201d to your computer and use it in GitHub Desktop.
Save igrr/1621cf555955cb7fb2de7efdd3be201d to your computer and use it in GitHub Desktop.
#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