Skip to content

Commit 0372d0d

Browse files
author
Me No Dev
committed
Merge remote-tracking branch 'esp8266/master'
2 parents 2491941 + 5c7b407 commit 0372d0d

File tree

11 files changed

+106
-22
lines changed

11 files changed

+106
-22
lines changed

Diff for: boards.txt

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ menu.FlashSize=Flash Size
44
menu.FlashMode=Flash Mode
55
menu.FlashFreq=Flash Frequency
66
menu.UploadTool=Upload Using
7+
menu.ResetMethod=Reset Method
78

89
##############################################################
910
generic.name=Generic ESP8266 Module
@@ -135,6 +136,11 @@ generic.menu.FlashSize.4M3M.build.spiffs_end=0x3FB000
135136
generic.menu.FlashSize.4M3M.build.spiffs_blocksize=8192
136137
generic.menu.FlashSize.4M3M.upload.maximum_size=1044464
137138

139+
generic.menu.ResetMethod.ck=ck
140+
generic.menu.ResetMethod.ck.upload.resetmethod=ck
141+
generic.menu.ResetMethod.nodemcu=nodemcu
142+
generic.menu.ResetMethod.nodemcu.upload.resetmethod=nodemcu
143+
138144
# disabled because espressif's bootloader refuses to write above 4M
139145
# generic.menu.FlashSize.8M=8M (7M SPIFFS)
140146
# generic.menu.FlashSize.8M.build.flash_size=1M

Diff for: cores/esp8266/FS.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,11 +174,11 @@ bool FS::format() {
174174
return _impl->format();
175175
}
176176

177-
bool FS::info(uint32_t *total, uint32_t *used){
177+
bool FS::info(FSInfo& info){
178178
if (!_impl) {
179179
return false;
180180
}
181-
return _impl->info(total,used);
181+
return _impl->info(info);
182182
}
183183

184184
File FS::open(const String& path, const char* mode) {

Diff for: cores/esp8266/FS.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,15 @@ class Dir {
8585
DirImplPtr _impl;
8686
};
8787

88+
struct FSInfo {
89+
size_t totalBytes;
90+
size_t usedBytes;
91+
size_t blockSize;
92+
size_t pageSize;
93+
size_t maxOpenFiles;
94+
size_t maxPathLength;
95+
};
96+
8897
class FS
8998
{
9099
public:
@@ -93,7 +102,7 @@ class FS
93102
bool begin();
94103

95104
bool format();
96-
bool info(uint32_t *total, uint32_t *used);
105+
bool info(FSInfo& info);
97106

98107
File open(const char* path, const char* mode);
99108
File open(const String& path, const char* mode);
@@ -123,6 +132,7 @@ using fs::SeekMode;
123132
using fs::SeekSet;
124133
using fs::SeekCur;
125134
using fs::SeekEnd;
135+
using fs::FSInfo;
126136

127137
extern FS SPIFFS;
128138

Diff for: cores/esp8266/FSImpl.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class FSImpl {
6464
public:
6565
virtual bool begin() = 0;
6666
virtual bool format() = 0;
67-
virtual bool info(uint32_t *total, uint32_t *used) = 0;
67+
virtual bool info(FSInfo& info) = 0;
6868
virtual FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) = 0;
6969
virtual bool exists(const char* path) = 0;
7070
virtual DirImplPtr openDir(const char* path) = 0;

Diff for: cores/esp8266/Updater.cpp

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
extern "C" {
99
#include "c_types.h"
1010
#include "spi_flash.h"
11+
#include "user_interface.h"
1112
}
1213

1314
extern "C" uint32_t _SPIFFS_start;
@@ -59,6 +60,8 @@ bool UpdaterClass::begin(size_t size, int command) {
5960
_reset();
6061
_error = 0;
6162

63+
wifi_set_sleep_type(NONE_SLEEP_T);
64+
6265
uint32_t updateStartAddress = 0;
6366
if (command == U_FLASH) {
6467
//size of current sketch rounded to a sector

Diff for: cores/esp8266/spiffs_api.cpp

+9-5
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,15 @@ class SPIFFSImpl : public FSImpl {
7171
}
7272
return true;
7373
}
74-
75-
bool info(uint32_t *total, uint32_t *used) override{
76-
auto rc = SPIFFS_info(&_fs, total, used);
77-
if (rc != SPIFFS_OK) {
78-
DEBUGV("SPIFFS_format: rc=%d, err=%d\r\n", rc, _fs.err_code);
74+
bool info(FSInfo& info) override {
75+
info.maxOpenFiles = _maxOpenFds;
76+
info.blockSize = _blockSize;
77+
info.pageSize = _pageSize;
78+
info.maxOpenFiles = _maxOpenFds;
79+
info.maxPathLength = SPIFFS_OBJ_NAME_LEN;
80+
auto rc = SPIFFS_info(&_fs, &info.totalBytes, &info.usedBytes);
81+
if (rc != SPIFFS_OK) {
82+
DEBUGV("SPIFFS_info: rc=%d, err=%d\r\n", rc, _fs.err_code);
7983
return false;
8084
}
8185
return true;

Diff for: doc/reference.md

+27-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ SweetPea ESP-210 | 4M | 1M, 3M
178178

179179
*ESP8266FS* is a tool which integrates into the Arduino IDE. It adds a menu item to *Tools* menu for uploading the contents of sketch data directory into ESP8266 flash file system.
180180

181-
- Download the tool: http://arduino.esp8266.com/ESP8266FS-1.6.5-1105-g98d2458.zip
181+
- Download the tool: https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.1.3/ESP8266FS-0.1.3.zip.
182182
- In your Arduino sketchbook directory, create `tools` directory if it doesn't exist yet
183183
- Unpack the tool into `tools` directory (the path will look like `<home_dir>/Arduino/tools/ESP8266FS/tool/esp8266fs.jar`)
184184
- Restart Arduino IDE
@@ -266,6 +266,32 @@ SPIFFS.rename(pathFrom, pathTo)
266266
Renames file from `pathFrom` to `pathTo`. Paths must be absolute. Returns *true*
267267
if file was renamed successfully.
268268

269+
#### info
270+
271+
```c++
272+
FSInfo fs_info;
273+
SPIFFS.info(fs_info);
274+
```
275+
276+
Fills [FSInfo structure](#filesystem-information-structure) with information about
277+
the file system. Returns `true` is successful, `false` otherwise.
278+
279+
### Filesystem information structure
280+
281+
```c++
282+
struct FSInfo {
283+
size_t totalBytes;
284+
size_t usedBytes;
285+
size_t blockSize;
286+
size_t pageSize;
287+
size_t maxOpenFiles;
288+
size_t maxPathLength;
289+
};
290+
```
291+
292+
This is the structure which may be filled using FS::info method. Field names
293+
are self-explanatory.
294+
269295
### Directory object (Dir)
270296
271297
The purpose of *Dir* object is to iterate over files inside a directory.

Diff for: libraries/ESP8266WebServer/src/ESP8266WebServer.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ void ESP8266WebServer::_addRequestHandler(RequestHandler* handler) {
8383
}
8484
}
8585

86-
void ESP8266WebServer::serveStatic(const char* uri, FS& fs, const char* path) {
87-
_addRequestHandler(new StaticRequestHandler(fs, path, uri));
86+
void ESP8266WebServer::serveStatic(const char* uri, FS& fs, const char* path, const char* cache_header) {
87+
_addRequestHandler(new StaticRequestHandler(fs, path, uri, cache_header));
8888
}
8989

9090
void ESP8266WebServer::handleClient() {

Diff for: libraries/ESP8266WebServer/src/ESP8266WebServer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ class ESP8266WebServer
6969
void on(const char* uri, THandlerFunction handler);
7070
void on(const char* uri, HTTPMethod method, THandlerFunction fn);
7171
void addHandler(RequestHandler* handler);
72-
void serveStatic(const char* uri, fs::FS& fs, const char* path);
72+
void serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_header = NULL );
7373
void onNotFound(THandlerFunction fn); //called when handler is not assigned
7474
void onFileUpload(THandlerFunction fn); //handle file uploads
7575

Diff for: libraries/ESP8266WebServer/src/detail/RequestHandlersImpl.h

+29-9
Original file line numberDiff line numberDiff line change
@@ -31,39 +31,57 @@ class FunctionRequestHandler : public RequestHandler {
3131

3232
class StaticRequestHandler : public RequestHandler {
3333
public:
34-
StaticRequestHandler(FS& fs, const char* path, const char* uri)
34+
StaticRequestHandler(FS& fs, const char* path, const char* uri, const char* cache_header)
3535
: _fs(fs)
3636
, _uri(uri)
3737
, _path(path)
38+
, _cache_header(cache_header)
3839
{
3940
_isFile = fs.exists(path);
40-
DEBUGV("StaticRequestHandler: path=%s uri=%s isFile=%d\r\n", path, uri, _isFile);
41-
_baseUriLength = _uri.length();
41+
DEBUGV("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header);
42+
_baseUriLength = _uri.length();
4243
}
43-
4444
bool handle(ESP8266WebServer& server, HTTPMethod requestMethod, String requestUri) override {
4545
if (requestMethod != HTTP_GET)
4646
return false;
4747
DEBUGV("StaticRequestHandler::handle: request=%s _uri=%s\r\n", requestUri.c_str(), _uri.c_str());
4848
if (!requestUri.startsWith(_uri))
49-
return false;
49+
return false;
50+
51+
String path(_path);
52+
53+
if(path.endsWith("/")) path += "index.htm";
5054

51-
String path(_path);
52-
if (!_isFile) {
55+
if (!_isFile) {
5356
// Base URI doesn't point to a file. Append whatever follows this
5457
// URI in request to get the file path.
55-
path += requestUri.substring(_baseUriLength);
58+
path += requestUri.substring(_baseUriLength);
5659
}
60+
5761
else if (requestUri != _uri) {
5862
// Base URI points to a file but request doesn't match this URI exactly
5963
return false;
6064
}
6165
DEBUGV("StaticRequestHandler::handle: path=%s, isFile=%d\r\n", path.c_str(), _isFile);
66+
67+
String contentType = getContentType(path);
68+
69+
// look for gz file, only if the original specified path is not a gz. So part only works to send gzip via content encoding when a non compressed is asked for
70+
// if you point the the path to gzip you will serve the gzip as content type "application/x-gzip", not text or javascript etc...
71+
if (!path.endsWith(".gz") && !SPIFFS.exists(path)) {
72+
String pathWithGz = path + ".gz";
73+
if(SPIFFS.exists(pathWithGz))
74+
path += ".gz";
75+
}
76+
6277
File f = _fs.open(path, "r");
6378
if (!f)
6479
return false;
6580

66-
server.streamFile(f, getContentType(path));
81+
if (_cache_header.length() != 0)
82+
server.sendHeader("Cache-Control", _cache_header);
83+
84+
server.streamFile(f, contentType);
6785
return true;
6886
}
6987

@@ -81,13 +99,15 @@ class StaticRequestHandler : public RequestHandler {
8199
else if (path.endsWith(".xml")) return "text/xml";
82100
else if (path.endsWith(".pdf")) return "application/pdf";
83101
else if (path.endsWith(".zip")) return "application/zip";
102+
else if(path.endsWith(".gz")) return "application/x-gzip";
84103
return "application/octet-stream";
85104
}
86105

87106
protected:
88107
FS _fs;
89108
String _uri;
90109
String _path;
110+
String _cache_header;
91111
bool _isFile;
92112
size_t _baseUriLength;
93113
};

Diff for: tests/FSWrapper/FSWrapper.ino

+15
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,21 @@ void setup() {
111111
}
112112
}
113113

114+
{
115+
FSInfo info;
116+
if (!SPIFFS.info(info)) {
117+
fail("info failed");
118+
}
119+
Serial.printf("Total: %u\nUsed: %u\nBlock: %u\nPage: %u\nMax open files: %u\nMax path len: %u\n",
120+
info.totalBytes,
121+
info.usedBytes,
122+
info.blockSize,
123+
info.pageSize,
124+
info.maxOpenFiles,
125+
info.maxPathLength
126+
);
127+
}
128+
114129
{
115130
if (!SPIFFS.format()) {
116131
fail("format failed");

0 commit comments

Comments
 (0)