From 6b51203b3baa491e598fdb67cf70d94872174230 Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Mon, 11 Jan 2021 17:44:54 +0100 Subject: [PATCH 1/2] file download ESP32 task --- tasmota/xdrv_50_filesystem.ino | 76 +++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 2 deletions(-) diff --git a/tasmota/xdrv_50_filesystem.ino b/tasmota/xdrv_50_filesystem.ino index d61093d02..56d4ecfd8 100644 --- a/tasmota/xdrv_50_filesystem.ino +++ b/tasmota/xdrv_50_filesystem.ino @@ -85,6 +85,8 @@ uint8_t ufs_dir; // 0 = none, 1 = SD, 2 = ffat, 3 = littlefs uint8_t ufs_type; uint8_t ffs_type; +bool download_busy; + /*********************************************************************************************/ @@ -459,6 +461,8 @@ void UfsDirectory(void) { strcpy(ufs_path, "/"); + + if (Webserver->hasArg("download")) { String stmp = Webserver->arg("download"); char *cp = (char*)stmp.c_str(); @@ -595,9 +599,10 @@ void UfsListDir(char *path, uint8_t depth) { } } + + uint8_t UfsDownloadFile(char *file) { File download_file; - WiFiClient download_Client; if (!dfsp->exists(file)) { AddLog_P(LOG_LEVEL_INFO, PSTR("UFS: File not found")); @@ -615,6 +620,8 @@ uint8_t UfsDownloadFile(char *file) { return 1; } +#ifdef ESP8266 + WiFiClient download_Client; uint32_t flen = download_file.size(); download_Client = Webserver->client(); @@ -634,7 +641,6 @@ uint8_t UfsDownloadFile(char *file) { uint8_t buff[512]; uint32_t bread; - // transfer is about 150kb/s uint32_t cnt = 0; while (download_file.available()) { @@ -650,12 +656,78 @@ uint8_t UfsDownloadFile(char *file) { //} } delay(0); + OsWatchLoop(); } download_file.close(); download_Client.stop(); +#endif // esp8266 + + +#ifdef ESP32 + download_file.close(); + + if (download_busy == true) { + AddLog_P(LOG_LEVEL_INFO, PSTR("UFS: Download is busy")); + return 0; + } + + download_busy = true; + char *path = (char*)malloc(128); + strcpy(path,file); + xTaskCreatePinnedToCore(donload_task, "DT", 6000, (void*)path, 3, NULL, 1); +#endif // ESP32 + return 0; } + +#ifdef ESP32 +#ifndef DOWNLOAD_SIZE +#define DOWNLOAD_SIZE 4096 +#endif +void donload_task(void *path) { + File download_file; + WiFiClient download_Client; + char *file = (char*) path; + + download_file = dfsp->open(file, UFS_FILE_READ); + free(file); + + uint32_t flen = download_file.size(); + + download_Client = Webserver->client(); + Webserver->setContentLength(flen); + + char attachment[100]; + char *cp; + for (uint32_t cnt = strlen(file); cnt >= 0; cnt--) { + if (file[cnt] == '/') { + cp = &file[cnt + 1]; + break; + } + } + snprintf_P(attachment, sizeof(attachment), PSTR("attachment; filename=%s"), cp); + Webserver->sendHeader(F("Content-Disposition"), attachment); + WSSend(200, CT_STREAM, ""); + + uint8_t *buff = (uint8_t*)malloc(DOWNLOAD_SIZE); + if (buff) { + uint32_t bread; + while (download_file.available()) { + bread = download_file.read(buff, DOWNLOAD_SIZE); + uint32_t bw = download_Client.write((const char*)buff, bread); + if (!bw) { break; } + } + free(buff); + } + download_file.close(); + download_Client.stop(); + download_busy = false; + vTaskDelete( NULL ); +} +#endif // ESP32 + + bool UfsUploadFileOpen(const char* upload_filename) { char npath[48]; snprintf_P(npath, sizeof(npath), PSTR("%s/%s"), ufs_path, upload_filename); From 816cbcafe1cc6328efd979f55a93700bd14a262d Mon Sep 17 00:00:00 2001 From: gemu2015 Date: Mon, 11 Jan 2021 17:45:06 +0100 Subject: [PATCH 2/2] fix pwm ESP32 --- tasmota/xdrv_10_scripter.ino | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tasmota/xdrv_10_scripter.ino b/tasmota/xdrv_10_scripter.ino index f850bb048..5f5c57405 100755 --- a/tasmota/xdrv_10_scripter.ino +++ b/tasmota/xdrv_10_scripter.ino @@ -4245,10 +4245,14 @@ int16_t Run_script_sub(const char *type, int8_t tlen, JsonParserObject *jo) { lp += 3; uint8_t channel = 1; if (*(lp+1)=='(') { - channel = *lp & 7; - if (channel > 5) { - channel = 5; - } + channel = *lp & 0x0f; +#ifdef ESP8266 + if (channel > 5) {channel = 5;} +#endif // ESP8266 +#ifdef ESP32 + if (channel > 8) {channel = 8;} +#endif // ESP32 + if (channel < 1) {channel = 1;} lp += 2; } else { if (*lp=='(') {