diff --git a/.gitmodules b/.gitmodules index b4ea7c1..445099c 100644 --- a/.gitmodules +++ b/.gitmodules @@ -43,3 +43,9 @@ [submodule "components/esp-nimble-cpp"] path = components/esp-nimble-cpp url = git@github.com:0xFEEDC0DE64/esp-nimble-cpp.git +[submodule "components/espasyncota"] + path = components/espasyncota + url = git@github.com:0xFEEDC0DE64/espasyncota.git +[submodule "components/esphttpdutils"] + path = components/esphttpdutils + url = git@github.com:0xFEEDC0DE64/esphttpdutils.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 1537f1f..2d0739c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,8 +41,7 @@ add_definitions( -DDEVICE_PREFIX=bobbyquad -DAP_PASSWORD=Passwort_123 -DFEATURE_WEBSERVER -# -DFEATURE_ARDUINOOTA -# -DFEATURE_WEBOTA + -DFEATURE_OTA -DFEATURE_DPAD_5WIRESW -DPINS_DPAD_5WIRESW_OUT=18 -DPINS_DPAD_5WIRESW_IN1=19 diff --git a/components/ArduinoJson b/components/ArduinoJson index 73a34f7..475a650 160000 --- a/components/ArduinoJson +++ b/components/ArduinoJson @@ -1 +1 @@ -Subproject commit 73a34f7d92125dd9e789ef499e13498ad0d69807 +Subproject commit 475a650703d203293e9037a9d0cfcbd3de17084f diff --git a/components/arduino-esp32 b/components/arduino-esp32 index ff9ec96..a84e053 160000 --- a/components/arduino-esp32 +++ b/components/arduino-esp32 @@ -1 +1 @@ -Subproject commit ff9ec961c1566d98ce39c3b97269c77d85fc69c0 +Subproject commit a84e0538ff20f1fbcd20fb47c836a67557677d89 diff --git a/components/cpputils b/components/cpputils index 89bff1a..faeacdc 160000 --- a/components/cpputils +++ b/components/cpputils @@ -1 +1 @@ -Subproject commit 89bff1a8dcac2f951ac3f2c3d7415691ce16ca12 +Subproject commit faeacdcfbfcfcf0804d64d839eb5ee14a5d84c35 diff --git a/components/espasyncota b/components/espasyncota new file mode 160000 index 0000000..b76c6c7 --- /dev/null +++ b/components/espasyncota @@ -0,0 +1 @@ +Subproject commit b76c6c7bf2c11ccf53f0c346b509848a59a0936b diff --git a/components/espchrono b/components/espchrono index 7f8a185..4d2e930 160000 --- a/components/espchrono +++ b/components/espchrono @@ -1 +1 @@ -Subproject commit 7f8a185678cccf0307910bffc6422a5564dccb0c +Subproject commit 4d2e9305dc8c434a7a5ddf5c534a3a896be04bee diff --git a/components/espcpputils b/components/espcpputils index 3a350f1..1ef4a9e 160000 --- a/components/espcpputils +++ b/components/espcpputils @@ -1 +1 @@ -Subproject commit 3a350f11897f8f82bfc906efb7fbebd14e7da352 +Subproject commit 1ef4a9ea561947fa327c59e54a0cef79f6817c46 diff --git a/components/esphttpdutils b/components/esphttpdutils new file mode 160000 index 0000000..a787113 --- /dev/null +++ b/components/esphttpdutils @@ -0,0 +1 @@ +Subproject commit a78711317ba4a5d5ee0ebf9e047a3609919ef898 diff --git a/components/espwifistack b/components/espwifistack index 79e5736..717d877 160000 --- a/components/espwifistack +++ b/components/espwifistack @@ -1 +1 @@ -Subproject commit 79e5736649a20f1a0e637efce8f96420df77e0cb +Subproject commit 717d877a44056c51e4a3ab777c4279c3d7a2e220 diff --git a/components/expected b/components/expected index aa9b2b2..30ee4ea 160000 --- a/components/expected +++ b/components/expected @@ -1 +1 @@ -Subproject commit aa9b2b2d1f3e23b2a3771afc6eda7f2244125da6 +Subproject commit 30ee4ea505463716b03d177d7e65174a697c9eb2 diff --git a/components/fmt b/components/fmt index 4b11c94..d3c349f 160000 --- a/components/fmt +++ b/components/fmt @@ -1 +1 @@ -Subproject commit 4b11c94036d4c5012dc4cb3854f47052f6f49812 +Subproject commit d3c349f69de79e0014e2e4fe1c4a1cd7c74983da diff --git a/esp-idf b/esp-idf index cd7cd9d..9e9abdf 160000 --- a/esp-idf +++ b/esp-idf @@ -1 +1 @@ -Subproject commit cd7cd9ddef731411b18b716bcddec2e62dc6b8f1 +Subproject commit 9e9abdf483b982210f04b869ea104ff56dd77827 diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index b7e12ea..c49bbb4 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -183,7 +183,7 @@ set(dependencies libsodium freertos nvs_flash esp_http_server esp_https_ota mdns app_update esp_system esp_websocket_client driver arduino-esp32 ArduinoJson esp-nimble-cpp bobbycar-protocol cpputils cxx-ring-buffer date - espchrono espcpputils espwifistack expected fmt TFT_eSPI + espasyncota espchrono espcpputils esphttpdutils espwifistack expected fmt TFT_eSPI ) idf_component_register( diff --git a/main/displays/updatedisplay.h b/main/displays/updatedisplay.h index 6231633..4fda54c 100644 --- a/main/displays/updatedisplay.h +++ b/main/displays/updatedisplay.h @@ -3,8 +3,8 @@ #include #include -#if defined(FEATURE_ARDUINOOTA) || defined(FEATURE_WEBOTA) -#include +#ifdef FEATURE_OTA +#include #endif #include "display.h" @@ -20,7 +20,7 @@ class StatusDisplay; } namespace { -#if defined(FEATURE_ARDUINOOTA) || defined(FEATURE_WEBOTA) +#ifdef FEATURE_OTA class UpdateDisplay : public Display, public DummyBack { public: @@ -36,8 +36,6 @@ public: bool m_finished; unsigned int m_progress; unsigned int m_total; - ota_error_t m_error; - bool m_errorValid; private: const std::string m_title; @@ -60,7 +58,6 @@ void UpdateDisplay::start() m_finished = false; m_progress = 0; m_total = 1; - m_errorValid = false; } void UpdateDisplay::initScreen() diff --git a/main/main.cpp b/main/main.cpp index 7102c52..2c24110 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -245,7 +245,7 @@ extern "C" void app_main() currentMode = &modes::defaultMode; -#ifdef FEATURE_ARDUINOOTA +#ifdef FEATURE_OTA bootLabel.redraw("ota"); initOta(); printMemoryStats("initOta()"); @@ -369,7 +369,7 @@ extern "C" void app_main() handleSerial(); -#ifdef FEATURE_ARDUINOOTA +#ifdef FEATURE_OTA handleOta(); #endif diff --git a/main/ota.h b/main/ota.h index 65712e2..0eb9c8c 100644 --- a/main/ota.h +++ b/main/ota.h @@ -1,7 +1,7 @@ #pragma once -#ifdef FEATURE_ARDUINOOTA -#include +#ifdef FEATURE_OTA +#include #endif #include "screens.h" @@ -9,41 +9,41 @@ #include "displays/updatedisplay.h" namespace { -#ifdef FEATURE_ARDUINOOTA +#ifdef FEATURE_OTA void initOta() { - ArduinoOTA - .onStart([]() { - std::string type; - switch (ArduinoOTA.getCommand()) - { - case U_FLASH: type = "sketch"; break; - case U_SPIFFS: type = "filesystem"; break; - default: type = "unknown"; - } - switchScreenImpl("Updating " + type); - }) - .onEnd([]() { - ((UpdateDisplay*)currentDisplay.get())->m_finished = true; - ((UpdateDisplay*)currentDisplay.get())->redraw(); - }) - .onProgress([](unsigned int progress, unsigned int total) { - ((UpdateDisplay*)currentDisplay.get())->m_progress = progress; - ((UpdateDisplay*)currentDisplay.get())->m_total = total; - ((UpdateDisplay*)currentDisplay.get())->redraw(); - }) - .onError([](ota_error_t error) { - ((UpdateDisplay*)currentDisplay.get())->m_error = error; - ((UpdateDisplay*)currentDisplay.get())->m_errorValid = true; - ((UpdateDisplay*)currentDisplay.get())->redraw(); - }); +// ArduinoOTA +// .onStart([]() { +// std::string type; +// switch (ArduinoOTA.getCommand()) +// { +// case U_FLASH: type = "sketch"; break; +// case U_SPIFFS: type = "filesystem"; break; +// default: type = "unknown"; +// } +// switchScreenImpl("Updating " + type); +// }) +// .onEnd([]() { +// ((UpdateDisplay*)currentDisplay.get())->m_finished = true; +// ((UpdateDisplay*)currentDisplay.get())->redraw(); +// }) +// .onProgress([](unsigned int progress, unsigned int total) { +// ((UpdateDisplay*)currentDisplay.get())->m_progress = progress; +// ((UpdateDisplay*)currentDisplay.get())->m_total = total; +// ((UpdateDisplay*)currentDisplay.get())->redraw(); +// }) +// .onError([](ota_error_t error) { +// ((UpdateDisplay*)currentDisplay.get())->m_error = error; +// ((UpdateDisplay*)currentDisplay.get())->m_errorValid = true; +// ((UpdateDisplay*)currentDisplay.get())->redraw(); +// }); - ArduinoOTA.begin(); +// ArduinoOTA.begin(); } void handleOta() { - ArduinoOTA.handle(); +// ArduinoOTA.handle(); } #endif } diff --git a/main/utils.h b/main/utils.h index 1e9f36c..5cce7a0 100644 --- a/main/utils.h +++ b/main/utils.h @@ -6,9 +6,6 @@ #include -#ifdef FEATURE_ARDUINOOTA -#include -#endif #ifdef FEATURE_SERIAL #include #endif @@ -123,22 +120,6 @@ std::string to_string(bobbycar::protocol::ControlMode value) return "Unknown ControlMode(" + std::to_string(int(value)) + ')'; } -#ifdef FEATURE_ARDUINOOTA -std::string to_string(ota_error_t value) -{ - switch (value) - { - case OTA_AUTH_ERROR: return "OTA_AUTH_ERROR"; - case OTA_BEGIN_ERROR: return "OTA_BEGIN_ERROR"; - case OTA_CONNECT_ERROR: return "OTA_CONNECT_ERROR"; - case OTA_RECEIVE_ERROR: return "OTA_RECEIVE_ERROR"; - case OTA_END_ERROR: return "OTA_END_ERROR"; - } - - return "Unknown ota_error_t(" + std::to_string(int(value)) + ')'; -} -#endif - std::array, 2> motorsInController(Controller &controller) { return {std::ref(controller.command.left), std::ref(controller.command.right)}; diff --git a/main/webserver.h b/main/webserver.h index 08f0d27..f035027 100644 --- a/main/webserver.h +++ b/main/webserver.h @@ -25,6 +25,7 @@ #include "displays/updatedisplay.h" //#include "esputils.h" #include "buttons.h" +#include "esphttpdutils.h" namespace { #ifdef FEATURE_WEBSERVER @@ -111,100 +112,6 @@ void initWebserver() //if (result != ESP_OK) // return result; } - -#ifdef FEATURE_WEBOTA - webServer.on("/update", HTTP_GET, [](AsyncWebServerRequest *request){ - request->send(200, "text/html", - "
" - "" - "" - "
" - "
" - "" - "" - "
"); - }); - - const auto handleUpdate = [](AsyncWebServerRequest *request){ - shouldReboot = !Update.hasError(); - - AsyncWebServerResponse *response = request->beginResponse(200, "text/plain", shouldReboot ? "OK" : "FAIL"); - response->addHeader("Connection", "close"); - request->send(response); - }; - - const auto createHandleUpdtateUpload = [](size_t size, int command){ - return [size, command](AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){ - //ESP_UNUSED(request) - - //Serial.printf("callback %u %u\r\n", index, len); - - if (!index) - { - //Serial.printf("Update Start: %s\r\n", filename.c_str()); - //Update.runAsync(true); - if (!Update.begin(size, command)) - Update.printError(Serial); - - std::string type; - if (ArduinoOTA.getCommand() == U_FLASH) - type = "sketch"; - else if (ArduinoOTA.getCommand() == U_SPIFFS) // U_SPIFFS - type = "filesystem"; - else - type = "unknown"; - - switchScreenImpl("Updating " + type); - } - - if (!Update.hasError()) - { - if (Update.write(data, len) == len) - { - ((UpdateDisplay*)currentDisplay.get())->m_progress = index; - ((UpdateDisplay*)currentDisplay.get())->m_total = size; - ((UpdateDisplay*)currentDisplay.get())->redraw(); - } - else - { - Update.printError(Serial); - - ((UpdateDisplay*)currentDisplay.get())->m_error = {}; - ((UpdateDisplay*)currentDisplay.get())->m_errorValid = true; - ((UpdateDisplay*)currentDisplay.get())->redraw(); - } - } - else - { - ((UpdateDisplay*)currentDisplay.get())->m_error = {}; - ((UpdateDisplay*)currentDisplay.get())->m_errorValid = true; - ((UpdateDisplay*)currentDisplay.get())->redraw(); - } - - if (final) - { - if (Update.end(true)) - { - //Serial.printf("Update Success: %uB\r\n", index + len); - - ((UpdateDisplay*)currentDisplay.get())->m_finished = true; - ((UpdateDisplay*)currentDisplay.get())->redraw(); - } - else - { - Update.printError(Serial); - - ((UpdateDisplay*)currentDisplay.get())->m_error = {}; - ((UpdateDisplay*)currentDisplay.get())->m_errorValid = true; - ((UpdateDisplay*)currentDisplay.get())->redraw(); - } - } - }; - }; - - webServer.on("/updateCode", HTTP_POST, handleUpdate, createHandleUpdtateUpload((ESP.getFreeSketchSpace() - 0x1000) & 0xFFFFF000, U_FLASH)); - webServer.on("/updateData", HTTP_POST, handleUpdate, createHandleUpdtateUpload(UPDATE_SIZE_UNKNOWN, U_SPIFFS)); -#endif } void handleWebserver() @@ -359,7 +266,7 @@ esp_err_t webserver_triggerItem_handler(httpd_req_t *req) if (const auto result = httpd_query_key_value(query.data(), indexParamName.data(), valueBufEncoded, 256); result == ESP_OK) { char valueBuf[257]; - espcpputils::urldecode(valueBuf, valueBufEncoded); + esphttpdutils::urldecode(valueBuf, valueBufEncoded); std::string_view value{valueBuf}; @@ -421,7 +328,7 @@ esp_err_t webserver_setValue_handler(httpd_req_t *req) if (const auto result = httpd_query_key_value(query.data(), valueParamName.data(), valueBufEncoded, 256); result == ESP_OK) { char valueBuf[257]; - espcpputils::urldecode(valueBuf, valueBufEncoded); + esphttpdutils::urldecode(valueBuf, valueBufEncoded); std::string_view value{valueBuf}; diff --git a/main/wifi_bobbycar.h b/main/wifi_bobbycar.h index e4b8cfe..6030203 100644 --- a/main/wifi_bobbycar.h +++ b/main/wifi_bobbycar.h @@ -12,40 +12,35 @@ wifi_stack::config wifi_create_config() return wifi_stack::config { .wifiEnabled = true, .hostname = deviceName, - .wifis = std::array { - wifi_stack::wifi_entry { .ssid = "realraum", .key = "r3alraum" }, - wifi_stack::wifi_entry { .ssid = "McDonalds Free WiFi", .key = "Passwort_123" }, - wifi_stack::wifi_entry { .ssid = "***REMOVED***", .key = "***REMOVED***" }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} }, - wifi_stack::wifi_entry { .ssid = {}, .key = {} } - }, - .sta_ip = { - .staticIpEnabled = false, -// .staticIp = {}, -// .staticGateway = {}, -// .staticSubnet = {}, -// .staticDns1 = {}, -// .staticDns2 = {} + .sta = { + .wifis = std::array { + wifi_stack::wifi_entry { .ssid = "realraum", .key = "r3alraum" }, + wifi_stack::wifi_entry { .ssid = "McDonalds Free WiFi", .key = "Passwort_123" }, + wifi_stack::wifi_entry { .ssid = "***REMOVED***", .key = "***REMOVED***" }, + wifi_stack::wifi_entry { .ssid = {}, .key = {} }, + wifi_stack::wifi_entry { .ssid = {}, .key = {} }, + wifi_stack::wifi_entry { .ssid = {}, .key = {} }, + wifi_stack::wifi_entry { .ssid = {}, .key = {} }, + wifi_stack::wifi_entry { .ssid = {}, .key = {} }, + wifi_stack::wifi_entry { .ssid = {}, .key = {} }, + wifi_stack::wifi_entry { .ssid = {}, .key = {} } + }, + .min_rssi = -90 }, .ap = { - { - .ssid = deviceName, - .key = STRING(AP_PASSWORD) + .ssid = deviceName, + .key = STRING(AP_PASSWORD), + .static_ip = { + .ip = {10, 0, 0, 1}, + .subnet = {255, 255, 255, 0}, + .gateway = {10, 0, 0, 1}, }, .channel = 1, .authmode = WIFI_AUTH_WPA2_PSK, .ssid_hidden = false, .max_connection = 4, - .beacon_interval = 100, - .ip = {10, 0, 0, 1}, - .subnet = {255, 255, 255, 0} - }, - .min_rssi = -90 + .beacon_interval = 100 + } }; }