diff --git a/ESP32_PrusaConnectCam/ESP32_PrusaConnectCam.ino b/ESP32_PrusaConnectCam/ESP32_PrusaConnectCam.ino index 23f9c74..145e4d3 100644 --- a/ESP32_PrusaConnectCam/ESP32_PrusaConnectCam.ino +++ b/ESP32_PrusaConnectCam/ESP32_PrusaConnectCam.ino @@ -8,12 +8,12 @@ This project uses other libraries. It is necessary to install them in the arduino IDE. - Library - License - Version - Link - - ESPAsyncWebServer - LGPL 3.0 - 3.0.6 - https://github.com/mathieucarbou/ESPAsyncWebServer - - AsyncTCP - LGPL 3.0 - 3.1.4 - https://github.com/mathieucarbou/AsyncTCP - - ArduinoJson - MIT - 7.1.0 - https://github.com/bblanchon/ArduinoJson + - ESPAsyncWebServer - LGPL 3.0 - 3.3.22 - https://github.com/mathieucarbou/ESPAsyncWebServer + - AsyncTCP - LGPL 3.0 - 3.2.14 - https://github.com/mathieucarbou/AsyncTCP + - ArduinoJson - MIT - 7.2.1 - https://github.com/bblanchon/ArduinoJson - ArduinoUniqueID - MIT - 1.3.0 - https://github.com/ricaun/ArduinoUniqueID - - arduino-esp32 - LGPL 2.1 - 3.0.4 - https://github.com/espressif/arduino-esp32 - - DHTnew - MIT - 0.4.20 - https://github.com/RobTillaart/DHTNew + - arduino-esp32 - LGPL 2.1 - 3.0.7 - https://github.com/espressif/arduino-esp32 + - DHTnew - MIT - 0.4.21 - https://github.com/RobTillaart/DHTNew Arduino IDE configuration for the MCU are stored in the module_XXX.h file. diff --git a/ESP32_PrusaConnectCam/WebServer.cpp b/ESP32_PrusaConnectCam/WebServer.cpp index 7ac17b8..33faf38 100644 --- a/ESP32_PrusaConnectCam/WebServer.cpp +++ b/ESP32_PrusaConnectCam/WebServer.cpp @@ -52,10 +52,19 @@ void Server_InitWebServer() { /* send photo with exif data */ SystemLog.AddEvent(LogLevel_Verbose, F("Send photo with EXIF data")); size_t total_len = SystemCamera.GetPhotoExifData()->len + SystemCamera.GetPhotoFb()->len - SystemCamera.GetPhotoExifData()->offset; - auto response = request->beginResponseStream("image/jpg"); + auto response = request->beginChunkedResponse("image/jpg", [total_len](uint8_t *buffer, size_t maxLen, size_t index) -> size_t { + size_t len = 0; + if (index < SystemCamera.GetPhotoExifData()->len) { + len = min(maxLen, SystemCamera.GetPhotoExifData()->len - index); + memcpy(buffer, SystemCamera.GetPhotoExifData()->header + index, len); + } else { + size_t offset = index - SystemCamera.GetPhotoExifData()->len + SystemCamera.GetPhotoExifData()->offset; + len = min(maxLen, SystemCamera.GetPhotoFb()->len - offset); + memcpy(buffer, SystemCamera.GetPhotoFb()->buf + offset, len); + } + return len; + }); response->addHeader("Content-Length", String(total_len)); - response->write(SystemCamera.GetPhotoExifData()->header, SystemCamera.GetPhotoExifData()->len); - response->write(&SystemCamera.GetPhotoFb()->buf[SystemCamera.GetPhotoExifData()->offset], SystemCamera.GetPhotoFb()->len - SystemCamera.GetPhotoExifData()->offset); request->send(response); } else { @@ -443,7 +452,7 @@ void Server_InitWebServer_Actions() { request->send(200, "text/plain", "Send Photo"); }); - /* route to toggle the LED on and off. If the LED is on, this route turns it off, and vice-versa. */ + /* route for change LED status */ server.on("/action_led", HTTP_GET, [](AsyncWebServerRequest* request) { SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: /action_led Change LED status")); if (Server_CheckBasicAuth(request) == false) @@ -455,7 +464,7 @@ void Server_InitWebServer_Actions() { request->send(200, "text/plain", "Change LED status"); }); - /* route to set the LED on or off manually */ + /* route for change LED status */ server.on("/light", HTTP_GET, [](AsyncWebServerRequest* request) { SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: /light set LED status")); if (Server_CheckBasicAuth(request) == false) @@ -511,7 +520,7 @@ void Server_InitWebServer_Actions() { ESP.restart(); }); - /* route for erasing the SD card */ + /* route for change LED status */ server.on("/action_sderase", HTTP_GET, [](AsyncWebServerRequest* request) { SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: /action_sderase remove files from SD card")); if (Server_CheckBasicAuth(request) == false)