Skip to content

Commit 2827e6e

Browse files
committed
ASync webserver
- Ported to async webserver for this to work: . all fs activity protected by update Mutex . inserted esp_task_wdt_reset(); several tight loops to prevent task watchdog panicing.
1 parent abf5fa3 commit 2827e6e

File tree

6 files changed

+458
-392
lines changed

6 files changed

+458
-392
lines changed

ReinagalerijV1.1.ino renamed to ReinaGalerij.ino

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#include "fsx.h"
22

33

4-
const char* PROGMEM esphostname = "reinagalerij";
4+
const char* PROGMEM esphostname = "reinASgalerij";
55
const char* PROGMEM sourcefile = __FILE__;
66
const char* PROGMEM compile_time = __DATE__ " " __TIME__;
77

8+
SemaphoreHandle_t fsSemaphore;
89

910
//---------------------------------------------------------------------------
1011
int make_dirtree( fs::FS &ff, String path ){
@@ -74,6 +75,7 @@ void setup(void) {
7475
tftSemaphore = xSemaphoreCreateMutex();;
7576
xSemaphoreTake(tftSemaphore, 10);
7677
xSemaphoreGive(tftSemaphore);
78+
7779

7880
mount_fs();
7981
startTFT();

apptft.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void showpicture( fs::FS &fs, const char *filename){
114114

115115
if ( xo || yo)tft.fillScreen(TFT_BLACK);
116116

117-
Serial.printf("%s Width = %d,height %d xo = %d, yo = %d\n",filename, w/scale,h/scale, xo,yo);
117+
//Serial.printf("%s Width = %d,height %d xo = %d, yo = %d\n",filename, w/scale,h/scale, xo,yo);
118118

119119
// Draw the image, top left at xo, yo
120120
//TJpgDec.drawFsJpg(xo, yo, filename);

fsx.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
#include <WiFiClient.h>
77
#include <esp_wifi.h>
88
#include <WiFiMulti.h>
9-
#include <WebServer.h>
9+
#include <AsyncTCP.h>
10+
#include <ESPAsyncWebServer.h>
1011
#include <ESPmDNS.h>
1112
#include <Update.h>
1213

1314
#include "soc/timer_group_struct.h"
1415
#include "soc/timer_group_reg.h"
16+
#include <esp_task_wdt.h>
1517
#include <dirent.h>
1618
#include <FS.h>
1719
#include <FFat.h>
@@ -99,13 +101,14 @@ static const char *cperror[7] PROGMEM = {"ok" ,
99101

100102

101103
extern std::vector<struct fsd> fsdlist;
102-
extern WebServer fsxserver;
104+
extern AsyncWebServer fsxserver;
103105
extern TaskHandle_t startwifiTask;
104106
extern TaskHandle_t FSXServerTask;
105107
extern TaskHandle_t tftshowTask;
106108
extern SemaphoreHandle_t updateSemaphore;
107109
extern SemaphoreHandle_t tftSemaphore;
108110

111+
109112
void fs2json( fs::FS &fs, const char *fsmount, const char *dirname, char **s , int depth = 0);
110113
void allfs2json( char **s);
111114
bool write_list( char *readbuffer, size_t len );

fsxcore.ino

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,13 +142,15 @@ void deltree( fs::FS *ff, const char *path ){
142142
while ( entry = dir.openNextFile() ){
143143

144144
if ( entry.isDirectory() ){
145-
deltree( ff, entry.name() );
145+
deltree( ff, entry.name() );
146+
esp_task_wdt_reset();
146147
} else{
147148
char* tmpname = strdup( entry.name() );
148149
entry.close();// openNextFile opens the file, LittleFS will refuse to delete the file if open;
149150
// FAT doesn't mind
150151
Serial.printf( "result of removing file %s: %d\n", tmpname, ff->remove( tmpname ) );
151152
free( tmpname );
153+
esp_task_wdt_reset();
152154
}
153155

154156
}
@@ -181,7 +183,8 @@ int copytree( fs::FS *sourcefs, String &sourcefspath, fs::FS *targetfs, String &
181183

182184
// copyfile will copy the file if source is a file, or create a directory if source is a directory
183185
result = copyfile( sourcefs, sourcefspath, targetfs, targetfspath);
184-
186+
esp_task_wdt_reset();
187+
185188
if(!dir.isDirectory() || result ){
186189
if( !dir.isDirectory() ) Serial.println(sourcefspath + " is a file\n");
187190
dir.close();
@@ -262,7 +265,8 @@ int copyfile( fs::FS *sourcefs, String &sourcefspath, fs::FS *targetfs, String &
262265
}
263266

264267
totalbytesread += bytesread;
265-
268+
esp_task_wdt_reset();
269+
266270
byteswritten = 0;
267271
while( byteswritten < bytesread ){
268272
writeresult= targetfile.write( &readbuffer[ byteswritten ], bytesread - byteswritten );

0 commit comments

Comments
 (0)