1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-25 20:02:37 +03:00

Merge remote-tracking branch 'esp8266/master'

This commit is contained in:
Me No Dev 2015-11-14 06:14:32 +02:00
commit 0372d0df1f
11 changed files with 106 additions and 22 deletions

View File

@ -4,6 +4,7 @@ menu.FlashSize=Flash Size
menu.FlashMode=Flash Mode
menu.FlashFreq=Flash Frequency
menu.UploadTool=Upload Using
menu.ResetMethod=Reset Method
##############################################################
generic.name=Generic ESP8266 Module
@ -135,6 +136,11 @@ generic.menu.FlashSize.4M3M.build.spiffs_end=0x3FB000
generic.menu.FlashSize.4M3M.build.spiffs_blocksize=8192
generic.menu.FlashSize.4M3M.upload.maximum_size=1044464
generic.menu.ResetMethod.ck=ck
generic.menu.ResetMethod.ck.upload.resetmethod=ck
generic.menu.ResetMethod.nodemcu=nodemcu
generic.menu.ResetMethod.nodemcu.upload.resetmethod=nodemcu
# disabled because espressif's bootloader refuses to write above 4M
# generic.menu.FlashSize.8M=8M (7M SPIFFS)
# generic.menu.FlashSize.8M.build.flash_size=1M

View File

@ -174,11 +174,11 @@ bool FS::format() {
return _impl->format();
}
bool FS::info(uint32_t *total, uint32_t *used){
bool FS::info(FSInfo& info){
if (!_impl) {
return false;
}
return _impl->info(total,used);
return _impl->info(info);
}
File FS::open(const String& path, const char* mode) {

View File

@ -85,6 +85,15 @@ protected:
DirImplPtr _impl;
};
struct FSInfo {
size_t totalBytes;
size_t usedBytes;
size_t blockSize;
size_t pageSize;
size_t maxOpenFiles;
size_t maxPathLength;
};
class FS
{
public:
@ -93,7 +102,7 @@ public:
bool begin();
bool format();
bool info(uint32_t *total, uint32_t *used);
bool info(FSInfo& info);
File open(const char* path, const char* mode);
File open(const String& path, const char* mode);
@ -123,6 +132,7 @@ using fs::SeekMode;
using fs::SeekSet;
using fs::SeekCur;
using fs::SeekEnd;
using fs::FSInfo;
extern FS SPIFFS;

View File

@ -64,7 +64,7 @@ class FSImpl {
public:
virtual bool begin() = 0;
virtual bool format() = 0;
virtual bool info(uint32_t *total, uint32_t *used) = 0;
virtual bool info(FSInfo& info) = 0;
virtual FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) = 0;
virtual bool exists(const char* path) = 0;
virtual DirImplPtr openDir(const char* path) = 0;

View File

@ -8,6 +8,7 @@
extern "C" {
#include "c_types.h"
#include "spi_flash.h"
#include "user_interface.h"
}
extern "C" uint32_t _SPIFFS_start;
@ -59,6 +60,8 @@ bool UpdaterClass::begin(size_t size, int command) {
_reset();
_error = 0;
wifi_set_sleep_type(NONE_SLEEP_T);
uint32_t updateStartAddress = 0;
if (command == U_FLASH) {
//size of current sketch rounded to a sector

View File

@ -71,11 +71,15 @@ public:
}
return true;
}
bool info(uint32_t *total, uint32_t *used) override{
auto rc = SPIFFS_info(&_fs, total, used);
if (rc != SPIFFS_OK) {
DEBUGV("SPIFFS_format: rc=%d, err=%d\r\n", rc, _fs.err_code);
bool info(FSInfo& info) override {
info.maxOpenFiles = _maxOpenFds;
info.blockSize = _blockSize;
info.pageSize = _pageSize;
info.maxOpenFiles = _maxOpenFds;
info.maxPathLength = SPIFFS_OBJ_NAME_LEN;
auto rc = SPIFFS_info(&_fs, &info.totalBytes, &info.usedBytes);
if (rc != SPIFFS_OK) {
DEBUGV("SPIFFS_info: rc=%d, err=%d\r\n", rc, _fs.err_code);
return false;
}
return true;

View File

@ -178,7 +178,7 @@ SweetPea ESP-210 | 4M | 1M, 3M
*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.
- Download the tool: http://arduino.esp8266.com/ESP8266FS-1.6.5-1105-g98d2458.zip
- Download the tool: https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.1.3/ESP8266FS-0.1.3.zip.
- In your Arduino sketchbook directory, create `tools` directory if it doesn't exist yet
- Unpack the tool into `tools` directory (the path will look like `<home_dir>/Arduino/tools/ESP8266FS/tool/esp8266fs.jar`)
- Restart Arduino IDE
@ -266,6 +266,32 @@ SPIFFS.rename(pathFrom, pathTo)
Renames file from `pathFrom` to `pathTo`. Paths must be absolute. Returns *true*
if file was renamed successfully.
#### info
```c++
FSInfo fs_info;
SPIFFS.info(fs_info);
```
Fills [FSInfo structure](#filesystem-information-structure) with information about
the file system. Returns `true` is successful, `false` otherwise.
### Filesystem information structure
```c++
struct FSInfo {
size_t totalBytes;
size_t usedBytes;
size_t blockSize;
size_t pageSize;
size_t maxOpenFiles;
size_t maxPathLength;
};
```
This is the structure which may be filled using FS::info method. Field names
are self-explanatory.
### Directory object (Dir)
The purpose of *Dir* object is to iterate over files inside a directory.

View File

@ -83,8 +83,8 @@ void ESP8266WebServer::_addRequestHandler(RequestHandler* handler) {
}
}
void ESP8266WebServer::serveStatic(const char* uri, FS& fs, const char* path) {
_addRequestHandler(new StaticRequestHandler(fs, path, uri));
void ESP8266WebServer::serveStatic(const char* uri, FS& fs, const char* path, const char* cache_header) {
_addRequestHandler(new StaticRequestHandler(fs, path, uri, cache_header));
}
void ESP8266WebServer::handleClient() {

View File

@ -69,7 +69,7 @@ public:
void on(const char* uri, THandlerFunction handler);
void on(const char* uri, HTTPMethod method, THandlerFunction fn);
void addHandler(RequestHandler* handler);
void serveStatic(const char* uri, fs::FS& fs, const char* path);
void serveStatic(const char* uri, fs::FS& fs, const char* path, const char* cache_header = NULL );
void onNotFound(THandlerFunction fn); //called when handler is not assigned
void onFileUpload(THandlerFunction fn); //handle file uploads

View File

@ -31,16 +31,16 @@ protected:
class StaticRequestHandler : public RequestHandler {
public:
StaticRequestHandler(FS& fs, const char* path, const char* uri)
StaticRequestHandler(FS& fs, const char* path, const char* uri, const char* cache_header)
: _fs(fs)
, _uri(uri)
, _path(path)
, _cache_header(cache_header)
{
_isFile = fs.exists(path);
DEBUGV("StaticRequestHandler: path=%s uri=%s isFile=%d\r\n", path, uri, _isFile);
DEBUGV("StaticRequestHandler: path=%s uri=%s isFile=%d, cache_header=%s\r\n", path, uri, _isFile, cache_header);
_baseUriLength = _uri.length();
}
bool handle(ESP8266WebServer& server, HTTPMethod requestMethod, String requestUri) override {
if (requestMethod != HTTP_GET)
return false;
@ -49,21 +49,39 @@ public:
return false;
String path(_path);
if(path.endsWith("/")) path += "index.htm";
if (!_isFile) {
// Base URI doesn't point to a file. Append whatever follows this
// URI in request to get the file path.
path += requestUri.substring(_baseUriLength);
}
else if (requestUri != _uri) {
// Base URI points to a file but request doesn't match this URI exactly
return false;
}
DEBUGV("StaticRequestHandler::handle: path=%s, isFile=%d\r\n", path.c_str(), _isFile);
String contentType = getContentType(path);
// 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
// if you point the the path to gzip you will serve the gzip as content type "application/x-gzip", not text or javascript etc...
if (!path.endsWith(".gz") && !SPIFFS.exists(path)) {
String pathWithGz = path + ".gz";
if(SPIFFS.exists(pathWithGz))
path += ".gz";
}
File f = _fs.open(path, "r");
if (!f)
return false;
server.streamFile(f, getContentType(path));
if (_cache_header.length() != 0)
server.sendHeader("Cache-Control", _cache_header);
server.streamFile(f, contentType);
return true;
}
@ -81,6 +99,7 @@ public:
else if (path.endsWith(".xml")) return "text/xml";
else if (path.endsWith(".pdf")) return "application/pdf";
else if (path.endsWith(".zip")) return "application/zip";
else if(path.endsWith(".gz")) return "application/x-gzip";
return "application/octet-stream";
}
@ -88,6 +107,7 @@ protected:
FS _fs;
String _uri;
String _path;
String _cache_header;
bool _isFile;
size_t _baseUriLength;
};

View File

@ -111,6 +111,21 @@ void setup() {
}
}
{
FSInfo info;
if (!SPIFFS.info(info)) {
fail("info failed");
}
Serial.printf("Total: %u\nUsed: %u\nBlock: %u\nPage: %u\nMax open files: %u\nMax path len: %u\n",
info.totalBytes,
info.usedBytes,
info.blockSize,
info.pageSize,
info.maxOpenFiles,
info.maxPathLength
);
}
{
if (!SPIFFS.format()) {
fail("format failed");