56 lines
1.8 KiB
C++
56 lines
1.8 KiB
C++
#include <ESPMegaWebServer.hpp>
|
|
|
|
ESPMegaWebServer::ESPMegaWebServer(uint16_t port, ESPMegaIoT *iot) {
|
|
this->port = port;
|
|
this->iot = iot;
|
|
this->server = new AsyncWebServer(port);
|
|
}
|
|
|
|
ESPMegaWebServer::~ESPMegaWebServer() {
|
|
delete this->server;
|
|
}
|
|
|
|
void ESPMegaWebServer::begin() {
|
|
this->server->begin();
|
|
auto bindedDashboardHandler = std::bind(&ESPMegaWebServer::dashboardHandler, this, std::placeholders::_1);
|
|
this->server->on("/", HTTP_GET, bindedDashboardHandler);
|
|
}
|
|
|
|
void ESPMegaWebServer::loop() {
|
|
// AsyncWebServer doesn't have a loop function
|
|
}
|
|
|
|
void ESPMegaWebServer::dashboardHandler(AsyncWebServerRequest *request) {
|
|
auto bindedDashboardProcessor = std::bind(&ESPMegaWebServer::dashboardProcessor, this, std::placeholders::_1);
|
|
request->send_P(200, "text/html", ota_html, bindedDashboardProcessor);
|
|
}
|
|
|
|
String ESPMegaWebServer::dashboardProcessor(const String& var) {
|
|
if (var == "hostname") {
|
|
return String(this->iot->getNetworkConfig()->hostname);
|
|
}
|
|
else if (var == "ip_address") {
|
|
return this->iot->getIp().toString();
|
|
}
|
|
else if (var == "mac_address") {
|
|
return this->iot->getMac();
|
|
}
|
|
else if (var == "model") {
|
|
return String("ESPMega PRO R3.3c");
|
|
}
|
|
else if (var == "mqtt_connection_string") {
|
|
MqttConfig *mqttConfig = this->iot->getMqttConfig();
|
|
String connectionString;
|
|
connectionString += mqttConfig->mqtt_server;
|
|
connectionString += ":";
|
|
connectionString += mqttConfig->mqtt_port;
|
|
return connectionString;
|
|
}
|
|
else if (var == "base_topic") {
|
|
return String(this->iot->getMqttConfig()->base_topic);
|
|
}
|
|
else if (var == "mqtt_connected") {
|
|
return this->iot->mqttConnected() ? "Connected" : "Standalone";
|
|
}
|
|
return "";
|
|
} |