From 721abe14e8ff92412a6f4803e2a1aaa0a831ce0c Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 20 Jul 2021 19:38:18 +0200 Subject: [PATCH] Updated espwifistack --- components/espwifistack | 2 +- main/mywifi.cpp | 2 +- main/webserver.cpp | 39 +++++++++++++++++++-------------------- 3 files changed, 21 insertions(+), 22 deletions(-) diff --git a/components/espwifistack b/components/espwifistack index 581b478..79e5736 160000 --- a/components/espwifistack +++ b/components/espwifistack @@ -1 +1 @@ -Subproject commit 581b478de00ef8b2854d43c1ec9a6bb8480a577c +Subproject commit 79e5736649a20f1a0e637efce8f96420df77e0cb diff --git a/main/mywifi.cpp b/main/mywifi.cpp index adfbade..7ebb17b 100644 --- a/main/mywifi.cpp +++ b/main/mywifi.cpp @@ -38,7 +38,7 @@ wifi_stack::config makeWifiConfig() wifi_stack::wifi_entry { .ssid = {}, .key = {} } }, .sta_ip = { - .dhcpEnabled = true, + .staticIpEnabled = false, // .staticIp = {}, // .staticGateway = {}, // .staticSubnet = {}, diff --git a/main/webserver.cpp b/main/webserver.cpp index 810bb23..1bc1fde 100644 --- a/main/webserver.cpp +++ b/main/webserver.cpp @@ -3,6 +3,7 @@ // system includes #include #include +#include // esp-idf includes #include @@ -34,6 +35,8 @@ constexpr const char * const TAG = "WEBSERVER"; template T htmlentities(const T &val) { return val; } // TODO template T htmlentities(T &&val) { return val; } // TODO +std::atomic shouldReboot; + esp_err_t webserver_root_handler(httpd_req_t *req); esp_err_t webserver_on_handler(httpd_req_t *req); esp_err_t webserver_off_handler(httpd_req_t *req); @@ -75,6 +78,12 @@ void update_webserver() { if (!config::enable_webserver.value()) return; + + if (shouldReboot) + { + shouldReboot = false; + esp_restart(); + } } namespace { @@ -132,9 +141,7 @@ esp_err_t webserver_root_handler(httpd_req_t *req) return result; CALL_AND_EXIT_ON_ERROR(httpd_resp_set_type, req, "text/html") - CALL_AND_EXIT_ON_ERROR(httpd_resp_send, req, body.data(), body.size()) - - return ESP_OK; + CALL_AND_EXIT(httpd_resp_send, req, body.data(), body.size()) } esp_err_t webserver_dht_display(httpd_req_t *req, std::string &body) @@ -469,7 +476,7 @@ esp_err_t webserver_on_handler(httpd_req_t *req) { if (!config::enable_lamp.value()) { ESP_LOGW(TAG, "lamp support not enabled!"); - CALL_AND_EXIT_ON_ERROR(httpd_resp_send_err, req, HTTPD_400_BAD_REQUEST, "lamp support not enabled!") + CALL_AND_EXIT(httpd_resp_send_err, req, HTTPD_400_BAD_REQUEST, "lamp support not enabled!") } const bool state = (lampState = true); @@ -480,16 +487,14 @@ esp_err_t webserver_on_handler(httpd_req_t *req) std::string_view body{"ON called..."}; CALL_AND_EXIT_ON_ERROR(httpd_resp_set_type, req, "text/html") - CALL_AND_EXIT_ON_ERROR(httpd_resp_send, req, body.data(), body.size()) - - return ESP_OK; + CALL_AND_EXIT(httpd_resp_send, req, body.data(), body.size()) } esp_err_t webserver_off_handler(httpd_req_t *req) { if (!config::enable_lamp.value()) { ESP_LOGW(TAG, "lamp support not enabled!"); - CALL_AND_EXIT_ON_ERROR(httpd_resp_send_err, req, HTTPD_400_BAD_REQUEST, "lamp support not enabled!") + CALL_AND_EXIT(httpd_resp_send_err, req, HTTPD_400_BAD_REQUEST, "lamp support not enabled!") } const bool state = (lampState = false); @@ -500,16 +505,14 @@ esp_err_t webserver_off_handler(httpd_req_t *req) std::string_view body{"OFF called..."}; CALL_AND_EXIT_ON_ERROR(httpd_resp_set_type, req, "text/html") - CALL_AND_EXIT_ON_ERROR(httpd_resp_send, req, body.data(), body.size()) - - return ESP_OK; + CALL_AND_EXIT(httpd_resp_send, req, body.data(), body.size()) } esp_err_t webserver_toggle_handler(httpd_req_t *req) { if (!config::enable_lamp.value()) { ESP_LOGW(TAG, "lamp support not enabled!"); - CALL_AND_EXIT_ON_ERROR(httpd_resp_send_err, req, HTTPD_400_BAD_REQUEST, "lamp support not enabled!") + CALL_AND_EXIT(httpd_resp_send_err, req, HTTPD_400_BAD_REQUEST, "lamp support not enabled!") } const bool state = (lampState = !lampState); @@ -520,20 +523,16 @@ esp_err_t webserver_toggle_handler(httpd_req_t *req) std::string_view body{"TOGGLE called..."}; CALL_AND_EXIT_ON_ERROR(httpd_resp_set_type, req, "text/html") - CALL_AND_EXIT_ON_ERROR(httpd_resp_send, req, body.data(), body.size()) - - return ESP_OK; + CALL_AND_EXIT(httpd_resp_send, req, body.data(), body.size()) } esp_err_t webserver_reboot_handler(httpd_req_t *req) { + shouldReboot = true; + std::string_view body{"REBOOT called..."}; CALL_AND_EXIT_ON_ERROR(httpd_resp_set_type, req, "text/html") - CALL_AND_EXIT_ON_ERROR(httpd_resp_send, req, body.data(), body.size()) - - esp_restart(); - - return ESP_OK; + CALL_AND_EXIT(httpd_resp_send, req, body.data(), body.size()) } } // namespace } // namespace deckenlampe