Update ESP Async Web server to from 2.10.8 to 3.0.3

pull/60/head
Miroslav Pivovarsky 2024-06-28 17:31:16 +02:00
parent ca31ea025f
commit df1f9e7f4a
4 changed files with 55 additions and 55 deletions

View File

@ -8,7 +8,7 @@
This project uses other libraries. It is necessary to install them in the arduino IDE.
- Library - License - Version - Link
- ESPAsyncWebServer - LGPL 3.0 - 2.10.8 - https://github.com/mathieucarbou/ESPAsyncWebServer
- ESPAsyncWebServer - LGPL 3.0 - 3.0.3 - 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
- ArduinoUniqueID - MIT - 1.3.0 - https://github.com/ricaun/ArduinoUniqueID

View File

@ -41,7 +41,7 @@ void Server_InitWebServer() {
return;
if (SystemCamera.GetCameraCaptureSuccess() == false) {
request->send_P(404, "text/plain", "Photo not found!");
request->send(404, "text/plain", "Photo not found!");
return;
}
SystemCamera.SetPhotoSending(true);
@ -61,7 +61,7 @@ void Server_InitWebServer() {
} else {
/* send photo without exif data */
SystemLog.AddEvent(LogLevel_Verbose, F("Send photo without EXIF data"));
request->send_P(200, "image/jpg", SystemCamera.GetPhotoFb()->buf, SystemCamera.GetPhotoFb()->len);
request->send(200, "image/jpg", SystemCamera.GetPhotoFb()->buf, SystemCamera.GetPhotoFb()->len);
}
SystemCamera.SetPhotoSending(false);
@ -102,7 +102,7 @@ void Server_InitWebServer_JsonData() {
SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: get json_input"));
if (Server_CheckBasicAuth(request) == false)
return;
request->send_P(200, F("text/plain"), Server_GetJsonData().c_str());
request->send(200, F("text/plain"), Server_GetJsonData().c_str());
});
/* route for json with wifi networks */
@ -110,7 +110,7 @@ void Server_InitWebServer_JsonData() {
SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: get json_wifi"));
if (Server_CheckBasicAuth(request) == false)
return;
request->send_P(200, F("text/plain"), SystemWifiMngt.GetAvailableWifiNetworks().c_str());
request->send(200, F("text/plain"), SystemWifiMngt.GetAvailableWifiNetworks().c_str());
});
/* route for san wi-fi networks */
@ -118,7 +118,7 @@ void Server_InitWebServer_JsonData() {
SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: scan WI-FI networks"));
if (Server_CheckBasicAuth(request) == false)
return;
request->send_P(200, F("text/html"), MSG_SCANNING);
request->send(200, F("text/html"), MSG_SCANNING);
SystemWifiMngt.ScanWiFiNetwork();
});
@ -168,7 +168,7 @@ void Server_InitWebServer_WebPages() {
SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: Get scripts.js"));
if (Server_CheckBasicAuth(request) == false)
return;
request->send_P(200, "application/javascript", scripts_js);
request->send(200, "application/javascript", scripts_js);
});
@ -254,7 +254,7 @@ void Server_InitWebServer_WebPages() {
request->send(SD_MMC, SystemLog.GetFilePath() + SystemLog.GetFileName(), "text/plain");
//SystemLog.LogOpenFile();
} else {
request->send_P(404, "text/plain", "Micro SD card not found with FAT32 partition!");
request->send(404, "text/plain", "Micro SD card not found with FAT32 partition!");
}
});
}
@ -404,7 +404,7 @@ void Server_InitWebServer_Actions() {
if (Server_CheckBasicAuth(request) == false)
return;
SystemCamera.CapturePhoto();
request->send_P(200, "text/plain", "Take Photo");
request->send(200, "text/plain", "Take Photo");
});
/* route for send photo to prusa backend */
@ -413,7 +413,7 @@ void Server_InitWebServer_Actions() {
if (Server_CheckBasicAuth(request) == false)
return;
Connect.SetSendingIntervalExpired();
request->send_P(200, "text/plain", "Send Photo");
request->send(200, "text/plain", "Send Photo");
});
/* route for change LED status */
@ -425,7 +425,7 @@ void Server_InitWebServer_Actions() {
SystemCamera.SetFlashStatus(!SystemCamera.GetFlashStatus());
SystemCamera.SetCameraFlashEnable(false);
request->send_P(200, "text/plain", "Change LED status");
request->send(200, "text/plain", "Change LED status");
});
/* route for change LED status */
@ -438,16 +438,16 @@ void Server_InitWebServer_Actions() {
SystemLog.AddEvent(LogLevel_Verbose, F("Turning light ON"));
SystemCamera.SetFlashStatus(true);
SystemCamera.SetCameraFlashEnable(false);
request->send_P(200, "text/plain", "Light ON");
request->send(200, "text/plain", "Light ON");
} else if (request->hasArg("off")) {
SystemLog.AddEvent(LogLevel_Verbose, F("Turning light OFF"));
SystemCamera.SetFlashStatus(false);
SystemCamera.SetCameraFlashEnable(false);
request->send_P(200, "text/plain", "Light OFF");
request->send(200, "text/plain", "Light OFF");
} else {
request->send_P(400, "text/plain", "Invalid request");
request->send(400, "text/plain", "Invalid request");
}
});
@ -461,16 +461,16 @@ void Server_InitWebServer_Actions() {
SystemLog.AddEvent(LogLevel_Verbose, F("Turning flash ON"));
SystemCamera.SetCameraFlashEnable(true);
SystemCamera.SetFlashStatus(false);
request->send_P(200, "text/plain", "Flash ON");
request->send(200, "text/plain", "Flash ON");
} else if (request->hasArg("off")) {
SystemLog.AddEvent(LogLevel_Verbose, F("Turning flash OFF"));
SystemCamera.SetCameraFlashEnable(false);
SystemCamera.SetFlashStatus(false);
request->send_P(200, "text/plain", "Flash OFF");
request->send(200, "text/plain", "Flash OFF");
} else {
request->send_P(400, "text/plain", "Invalid request");
request->send(400, "text/plain", "Invalid request");
}
});
@ -479,7 +479,7 @@ void Server_InitWebServer_Actions() {
SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: /action_reboo reboot MCU!"));
if (Server_CheckBasicAuth(request) == false)
return;
request->send_P(200, F("text/html"), MSG_REBOOT_MCU);
request->send(200, F("text/html"), MSG_REBOOT_MCU);
delay(100); /* wait for sending data */
ESP.restart();
});
@ -492,7 +492,7 @@ void Server_InitWebServer_Actions() {
StartRemoveSdCard = 1;
request->send_P(200, F("text/plain"), "Starting remove files from SD card");
request->send(200, F("text/plain"), "Starting remove files from SD card");
});
}
@ -637,7 +637,7 @@ void Server_InitWebServer_Sets() {
}
if (true == response) {
request->send_P(200, F("text/html"), response_msg.c_str());
request->send(200, F("text/html"), response_msg.c_str());
}
});
@ -756,7 +756,7 @@ void Server_InitWebServer_Sets() {
}
if (true == response) {
request->send_P(200, F("text/html"), MSG_SAVE_OK);
request->send(200, F("text/html"), MSG_SAVE_OK);
}
});
@ -765,7 +765,7 @@ void Server_InitWebServer_Sets() {
SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: /set_token"));
if (Server_CheckBasicAuth(request) == false)
return;
request->send_P(200, F("text/html"), MSG_SAVE_OK);
request->send(200, F("text/html"), MSG_SAVE_OK);
if (request->hasParam("token")) {
Connect.SetToken(request->getParam("token")->value());
@ -777,7 +777,7 @@ void Server_InitWebServer_Sets() {
SystemLog.AddEvent(LogLevel_Verbose, F("WEB server: /set_hostname"));
if (Server_CheckBasicAuth(request) == false)
return;
request->send_P(200, F("text/html"), MSG_SAVE_OK);
request->send(200, F("text/html"), MSG_SAVE_OK);
if (request->hasParam("hostname")) {
Connect.SetPrusaConnectHostname(request->getParam("hostname")->value());
@ -805,14 +805,14 @@ void Server_InitWebServer_Sets() {
/* check min and max length WI-FI ssid and password */
if (((TmpPassword.length() > 0) && (TmpSsid.length() > 0)) && ((TmpPassword.length() < EEPROM_ADDR_WIFI_PASSWORD_LENGTH) && (TmpSsid.length() < EEPROM_ADDR_WIFI_SSID_LENGTH))) {
/* send OK response */
request->send_P(200, F("text/html"), MSG_SAVE_OK_WIFI);
request->send(200, F("text/html"), MSG_SAVE_OK_WIFI);
/* save ssid and password */
SystemWifiMngt.SetStaCredentials(TmpSsid,TmpPassword);
SystemWifiMngt.WiFiStaConnect();
} else {
request->send_P(200, F("text/html"), MSG_SAVE_NOTOK);
request->send(200, F("text/html"), MSG_SAVE_NOTOK);
}
});
@ -856,10 +856,10 @@ void Server_InitWebServer_Sets() {
SystemWifiMngt.SetNetworkConfig(tmpIp, tmpMask, tmpGw, tmpDns);
/* send OK response */
request->send_P(200, F("text/html"), MSG_SAVE_OK_REBOOT);
request->send(200, F("text/html"), MSG_SAVE_OK_REBOOT);
} else {
request->send_P(200, F("text/html"), MSG_SAVE_NOTOK);
request->send(200, F("text/html"), MSG_SAVE_NOTOK);
}
});
@ -910,12 +910,12 @@ void Server_InitWebServer_Sets() {
/* send OK response */
if (true == ret) {
request->send_P(200, F("text/html"), MSG_SAVE_OK);
request->send(200, F("text/html"), MSG_SAVE_OK);
} else {
String msg = MSG_SAVE_NOTOK;
msg += " " + ret_msg;
request->send_P(200, F("text/html"), msg.c_str());
request->send(200, F("text/html"), msg.c_str());
}
});
@ -924,7 +924,7 @@ void Server_InitWebServer_Sets() {
SystemLog.AddEvent(LogLevel_Info, F("WEB server: /set_firmware_size"));
if (Server_CheckBasicAuth(request) == false)
return;
request->send_P(200, F("text/html"), MSG_SAVE_OK);
request->send(200, F("text/html"), MSG_SAVE_OK);
/* check cfg for flash */
if (request->hasParam("size")) {
@ -943,12 +943,12 @@ void Server_InitWebServer_Sets() {
if (request->hasParam("mdns")) {
String tmp = request->getParam("mdns")->value();
if (tmp.length() < EEPROM_ADDR_MDNS_RECORD_LENGTH) {
request->send_P(200, F("text/html"), MSG_SAVE_OK_REBOOT);
request->send(200, F("text/html"), MSG_SAVE_OK_REBOOT);
SystemWifiMngt.SetMdns(tmp);
} else {
String msg = "Error save mDNS. Maximum length: " + String(EEPROM_ADDR_MDNS_RECORD_LENGTH);
request->send_P(200, F("text/html"), msg.c_str());
request->send(200, F("text/html"), msg.c_str());
}
}
});
@ -1018,7 +1018,7 @@ void Server_InitWebServer_Update() {
SystemLog.AddEvent(LogLevel_Info, F("WEB server: /web_ota_update"));
if (Server_CheckBasicAuth(request) == false)
return;
request->send_P(200, F("text/html"), MSG_UPDATE_START);
request->send(200, F("text/html"), MSG_UPDATE_START);
FirmwareUpdate.Processing = true;
/* check flag */
@ -1039,7 +1039,7 @@ void Server_InitWebServer_Update() {
return;
System_CheckNewVersion();
request->send_P(200, F("text/html"), FirmwareUpdate.CheckNewVersionFwStatus.c_str());
request->send(200, F("text/html"), FirmwareUpdate.CheckNewVersionFwStatus.c_str());
});
}
@ -1080,7 +1080,7 @@ void Server_resume() {
* @param const char* - data
*/
void Server_handleCacheRequest(AsyncWebServerRequest* request, const char *contentType, const char *data) {
AsyncWebServerResponse *response = request->beginResponse_P(200, contentType, data);
AsyncWebServerResponse *response = request->beginResponse(200, contentType, data);
response->addHeader("Cache-Control", "public, max-age=" + String(WEB_CACHE_INTERVAL));
request->send(response);
}

View File

@ -14,15 +14,15 @@
#define _MCU_CFG_H_
/* ----------------- CAMERA TYPE ---------------*/
#define AI_THINKER_ESP32_CAM true
#define ESP32_WROVER_DEV false
#define CAMERA_MODEL_ESP32_S3_DEV_CAM false
#define CAMERA_MODEL_ESP32_S3_EYE_2_2 false
#define AI_THINKER_ESP32_CAM true
#define ESP32_WROVER_DEV false
#define CAMERA_MODEL_ESP32_S3_DEV_CAM false
#define CAMERA_MODEL_ESP32_S3_EYE_2_2 false
#define CAMERA_MODEL_XIAO_ESP32_S3_CAM false
#define CAMERA_MODEL_ESP32_S3_CAM false
#define CAMERA_MODEL_ESP32_S3_CAM false
/* ---------------- BASIC MCU CFG --------------*/
#define SW_VERSION "1.1.0-rc1" ///< SW version
#define SW_VERSION "1.1.0-rc1" ///< SW version
#define SW_BUILD __DATE__ " " __TIME__ ///< build number
#define CONSOLE_VERBOSE_DEBUG false ///< enable/disable verbose debug log level for console
#define DEVICE_HOSTNAME "Prusa-ESP32cam" ///< device hostname
@ -55,7 +55,7 @@
#define WEB_SERVER_PORT 80 ///< WEB server port
#define SERIAL_PORT_SPEED 115200 ///< baud rate
#define WDG_TIMEOUT 40000 ///< wdg timeout [second]
#define PHOTO_FRAGMENT_SIZE 5120 ///< photo fragmentation size [bytes]
#define PHOTO_FRAGMENT_SIZE 2048 ///< photo fragmentation size [bytes]
#define LOOP_DELAY 100 ///< loop delay [ms]
#define WIFI_CLIENT_WAIT_CON false ///< wait for connecting to WiFi network
#define WEB_CACHE_INTERVAL 86400 ///< cache interval for browser [s] 86400s = 24h

View File

@ -9,23 +9,23 @@
Board configuration in the arduino IDE 2.3.2
Tools -> Board -> ESP32 Arduino -> ESP32S3 Dev Module
Tools -> USB CDC on BOOT -> Enabled
Tools -> CPU Frequency -> 240MHz (WiFi/BT)
Tools -> CPU Frequency -> 160MHz (WiFi/BT)
Tools -> Core debug level -> None
Tools -> USB DFU on BOOT -> Disable
Tools -> Events Run On -> Core 1
Tools -> Events Run On -> Core 0
Tools -> Flash Mode -> DIO 80MHz
Tools -> Flash Size -> 16MB
Tools -> Jtag Adapter -> Disable
Tools -> Arduino Runs On -> Core 1
Tools -> Arduino Runs On -> Core 0
Tools -> USB Firmware MSC On Boot -> Disable
Tools -> Partition scheme -> Minimal SPIFFS (1.9MB APP with OTA/190KB SPIFFS)
Tools -> PSRAM -> QSPI PSRAM
Tools -> Upload Mode -> UART0 / Hardware CDC
Tools -> PSRAM -> OPI PSRAM
Tools -> Upload Mode -> USB-OTG CDC (TinyUSB)
Tools -> Upload Speed -> 921600
Tools -> USB Mode -> Hardware CDC & JTAG
Tools -> Zigbee mode -> Disable
Left USB-C connector is for programming and serial monitor
Right USB-C connector is for programming and serial monitor
@bug: Currently SW don't work with this DEV board. WiFi and MicroSD is not working
@ -57,12 +57,12 @@
/* ------------------ MCU CFG ------------------*/
#define ENABLE_BROWN_OUT_DETECTION false ///< Enable brown out detection
#define ENABLE_PSRAM true ///< Enable PSRAM
#define ENABLE_PSRAM true ///< Enable PSRAM
/* --------------- OTA UPDATE CFG --------------*/
#define OTA_UPDATE_FW_FILE PSTR("ESP32S3_DEV_CAM.bin") ///< OTA update firmware file name
#define FW_STATUS_LED_PIN 34 ///< GPIO pin for status FW update LED
#define FW_STATUS_LED_LEVEL_ON LOW ///< GPIO pin level for status LED ON
#define FW_STATUS_LED_LEVEL_ON LOW ///< GPIO pin level for status LED ON
/* --------------- FLASH LED CFG ---------------*/
#define ENABLE_CAMERA_FLASH false ///< Enable camera flash function
@ -76,20 +76,20 @@
#define FLASH_PWM_RESOLUTION 8 ///< range 1-20bit. 8bit = 0-255 range
/* --------------- SD CARD CFG ---------------*/
#define ENABLE_SD_CARD true ///< Enable SD card function
#define ENABLE_SD_CARD true ///< Enable SD card function
#define SD_PIN_CLK 42 ///< GPIO pin for SD card clock
#define SD_PIN_CMD 39 ///< GPIO pin for SD card command
#define SD_PIN_DATA0 41 ///< GPIO pin for SD card data 0
/* ---------- RESET CFG CONFIGURATION ----------*/
#define CFG_RESET_PIN 2 ///< GPIO 16 is for reset CFG to default
#define CFG_RESET_LED_PIN 34 ///< GPIO for indication of reset CFG
#define CFG_RESET_PIN 2 ///< GPIO 16 is for reset CFG to default
#define CFG_RESET_LED_PIN 34 ///< GPIO for indication of reset CFG
#define CFG_RESET_LED_LEVEL_ON LOW ///< GPIO pin level for status LED ON
/* -------------- STATUS LED CFG ----------------*/
#define STATUS_LED_ENABLE true ///< enable/disable status LED
#define STATUS_LED_GPIO_NUM 34 ///< GPIO pin for status LED
#define STATUS_LED_OFF_PIN_LEVEL LOW ///< GPIO pin level for status LED ON
#define STATUS_LED_OFF_PIN_LEVEL LOW ///< GPIO pin level for status LED ON
#endif // ESP32_WROVER_DEV
#endif // CAMERA_MODEL_ESP32_S3_DEV_CAM
/* EOF */