This repository was archived by the owner on Jan 20, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
This repository was archived by the owner on Jan 20, 2025. It is now read-only.
Using in other class (*.h/*.cpp) #225
Copy link
Copy link
Closed
Description
I'm trying to use AsyncWebServer in a custom class I'm making.
My WebHandlerClass.h looks as follows:
// WebHandler.h
#ifndef _WEBHANDLER_h
#define _WEBHANDLER_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#include <Hash.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
class WebHandlerClass
{
protected:
AsyncWebServer _server;
AsyncWebSocket _ws;
void _WsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t *data, size_t len);
public:
void init(int webPort);
void loop();
};
extern WebHandlerClass WebHandler;
#endifAnd my WebHandler.cpp like this:
// WebHandler.cpp
#include "WebHandler.h"
void WebHandlerClass::_WsEvent(AsyncWebSocket * server, AsyncWebSocketClient * client, AwsEventType type, void * arg, uint8_t * data, size_t len)
{
//removed for readability
}
void WebHandlerClass::init(int webPort)
{
AsyncWebServer _server(webPort);
AsyncWebSocket _ws("/ws");
//ws.onEvent(std::bind(&Asy);
//using namespace std::placeholders;
_ws.onEvent(std::bind(&WebHandlerClass::_WsEvent, this
, std::placeholders::_1
, std::placeholders::_2
, std::placeholders::_3
, std::placeholders::_4
, std::placeholders::_5
, std::placeholders::_6));
_server.begin();
}
void WebHandlerClass::loop()
{
}
WebHandlerClass WebHandler;In my main *.ino file I have the following line in place to initialize the WebHandler class:
WebHandler.init(80);
When I try to compile this I get the following error:
WebHandler.h: 17:7: error: no matching function for call to 'AsyncWebServer::AsyncWebServer()
Which makes me think this library doesn't support setting the port number after initialization.
Is there a way I can initialize the AsyncWebServer object without port number and later on reinitialize it?
Metadata
Metadata
Assignees
Labels
No labels