diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.cpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.cpp index 06c1618..f6fe70e 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.cpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.cpp @@ -75,13 +75,19 @@ void ESPMegaRecovery::enterRecoveryMode() { this->web_server->loadCredentialsFromFRAM(); ESP_LOGI("ESPMegaRecovery", "Aquiring the web server instance"); AsyncWebServer *server = this->web_server->getServer(); + server->begin(); // Add OTA update and restart endpoint ESP_LOGI("ESPMegaRecovery", "Adding OTA update and reboot endpoints"); + auto bindedDashboardHandler = std::bind(&ESPMegaWebServer::dashboardHandler, this->web_server, std::placeholders::_1); auto bindedOtaRequestHandler = std::bind(&ESPMegaWebServer::otaRequestHandler, this->web_server, std::placeholders::_1); auto bindedOtaUploadHandler = std::bind(&ESPMegaWebServer::otaUploadHandler, this->web_server, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6); + auto bindedDeviceInfoHandler = std::bind(&ESPMegaRecovery::getDeviceInfoHandler, this, std::placeholders::_1); + auto bindedConfigHandler = std::bind(&ESPMegaRecovery::configHandler, this, std::placeholders::_1); + server->on("/", HTTP_GET, bindedDashboardHandler); server->on("/ota_update", HTTP_POST, bindedOtaRequestHandler, bindedOtaUploadHandler); server->on("/reboot", HTTP_GET, std::bind(&ESPMegaWebServer::rebootHandler, this->web_server, std::placeholders::_1)); - + server->on("/get_device_info", HTTP_GET, bindedDeviceInfoHandler); + server->on("/config", HTTP_GET, bindedConfigHandler); } void ESPMegaRecovery::bindFRAM(FRAM *fram, uint32_t address) { this->fram = fram; @@ -105,3 +111,31 @@ void ESPMegaRecovery::resetBootloopCounter() { bool ESPMegaRecovery::isRecoveryMode() { return this->recovery_mode; } + +void ESPMegaRecovery::getDeviceInfoHandler(AsyncWebServerRequest *request) { + if (!request->authenticate(this->web_server->getWebUsername(), this->web_server->getWebPassword())) + { + return request->requestAuthentication(); + } + StaticJsonDocument<512> doc; + doc["hostname"] = this->iot->getNetworkConfig()->hostname; + doc["ip_address"] = this->iot->getIp().toString(); + doc["mac_address"] = this->iot->getMac(); + doc["model"] = BOARD_MODEL; + doc["mqtt_server"] = "Recovery"; + doc["mqtt_port"] = "Mode"; + doc["base_topic"] = "Recovery Mode"; + doc["mqtt_connected"] = "Recovery Mode"; + doc["software_version"] = "EMG-SAFE-1.0.0"; + doc["sdk_version"] = SDK_VESRION; + doc["idf_version"] = IDF_VER; + char buffer[512]; + serializeJson(doc, buffer); + request->send(200, "application/json", buffer); +} + +void ESPMegaRecovery::configHandler(AsyncWebServerRequest *request){ + // Say Not Available in Recovery Mode + // Wait 3s then redirect to / + request->send(500, "text/html", "
Configuration is not available in recovery mode
"); +} \ No newline at end of file diff --git a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.hpp b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.hpp index a8e9662..407e3eb 100644 --- a/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.hpp +++ b/ESPMegaPRO-OS-SDK/lib/ESPMegaPRO/ESPMegaRecovery.hpp @@ -25,7 +25,8 @@ public: void resetBootloopCounter(); // Reset the bootloop counter bool isRecoveryMode(); // Check if the device is in recovery mode private: - + void getDeviceInfoHandler(AsyncWebServerRequest *request); + void configHandler(AsyncWebServerRequest *request); FRAM* fram; uint32_t fram_address; uint8_t bootloop_counter; diff --git a/ESPMegaPRO-OS-SDK/src/main.cpp b/ESPMegaPRO-OS-SDK/src/main.cpp index 10419de..e8e43af 100644 --- a/ESPMegaPRO-OS-SDK/src/main.cpp +++ b/ESPMegaPRO-OS-SDK/src/main.cpp @@ -14,7 +14,7 @@ // #define FRAM_DEBUG // #define MQTT_DEBUG -// #define WRITE_DEFAULT_NETCONF +#define WRITE_DEFAULT_NETCONF //#define CLIMATE_CARD_ENABLE #define MQTT_CARD_REGISTER #define DISPLAY_ENABLE