B4R Library rESP8266FileSystem (SPIFFS)

ESP8266 comes with built-in file system provisioned on the chip flash. The file system is useful for storing persistent information.

The size available varies but on most devices it is more than 1mb. See the table here: https://github.com/esp8266/Arduino/blob/master/doc/filesystem.rst

rESP8266FileSystem API is almost identical to rSD API: https://www.b4x.com/android/forum/threads/sd-cards.65994/#content

A modified version of the file transfer example is attached.
You need to run the B4J program and the B4R program.
It supports uploading and downloading files.

The file system has some limitations, see this link for more information: https://github.com/esp8266/Arduino/blob/master/doc/filesystem.rst#file-system-limitations

Updates

This library is now an internal library.
V1.10 adds support for ESP32 boards.
You need to add this line to the main module when compiling to ESP32:
B4X:
#DefineExtra: #define SKIP_B4RNEW
 

Attachments

  • B4J_FileTransfer.zip
    3.4 KB · Views: 758
  • B4R_FileTransfer.zip
    1.6 KB · Views: 881
Last edited:

max123

Well-Known Member
Licensed User
Longtime User
Last edited:

max123

Well-Known Member
Licensed User
Longtime User
I've tried this but without success on my NodeMCU.

I compile OK, but when I press "List File" button on B4J app, ESP start to list all flash files and then crashes...
I've encountered many times this error using Arduino IDE, usually putting a yield() within a long loop prevent a watchdog timer to overflow and
solves the problem.To speed up the execution, yield() can be called not all times, but just every tot time, in C++ eg. like this:

B4X:
 if ((count % 1000) == 0) yield();

What is equivalent to yield() on B4R? I can use Delay(0)?

I attached my log:
 
Last edited:

max123

Well-Known Member
Licensed User
Longtime User
Yes, Bingo!

It works without need of WDT reset, just increased the StackBufferSize to 2000 bytes

But now I've a new problem, I count files with this code, it count 118 files and this is ok, but the log show a strange result as count of files...
See on the log a number inside a first square bracket, as you can see strange results. I use a local UInt variable to count all files, if I declare fileCount as Global do not work at all.

This is the code:
B4X:
Sub ListFiles
    Dim fileCount As UInt = 0
    For Each f As File In fs.ListFiles("/")
        fileCount = fileCount + 1
        Log("[", fileCount, "]   [ ", f.Name, " ]    ", f.Size, " bytes     StackBufferUsage: ", StackBufferUsage)
        astream.Write(f.Name).Write(Array As Byte(10))
    Next
    astream.Write(Array As Byte(0xff, 0xff, 0xff))
End Sub
This is my log:
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…