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: 849
  • B4R_FileTransfer.zip
    1.6 KB · Views: 953
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:
AppStart
Connecting To Telecom-59027407
Connected!
My IP Address: 192.168.1.4
fs Initialize result: 1
Total size: 2880 KB
Used size: 1938 KB
/frame10.bmp
/frame100.bmp
/frame73.bmp
/frame101.bmp
/frame89.bmp
/frame102.bmp
/frame103.bmp
/frame104.bmp
/frame105.bmp
/frame9.bmp
/frame106.bmp
/frame74.bmp
/frame107.bmp
/frame108.bmp
/frame109.bmp
/frame90.bmp
/frame11.bmp
/frame110.bmp
/frame75.bmp
/frame111.bmp
/frame91.bmp
/frame112.bmp
/frame113.bmp
/frame114.bmp
/frame115.bmp
/frame92.bmp
/frame116.bmp
/frame76.bmp
/frame117.bmp
/frame118.bmp
/frame12.bmp
/frame93.bmp
/frame13.bmp
/frame14.bmp
/frame77.bmp
/frame15.bmp
/frame16.bmp
/frame94.bmp
/frame17.bmp
/frame18.bmp
/frame19.bmp
/frame2.bmp
/frame78.bmp
/frame95.bmp
/frame20.bmp
/frame21.bmp
/frame22.bmp
/frame96.bmp
/frame23.bmp
/frame24.bmp
Exception (28):
epc1=0x40202133 epc2=0x00000000 epc3=0x00000000 excvaddr=0x0000000d depc=0x00000000
ctx: cont
sp: 3ffeff30 End: 3fff02a0 offset: 01a0
>>>stack>>>
3fff00d0: 3fff0110 00000001 3ffef1bc 40209921
3fff00e0: 3fff13a4 00000000 00000000 40209934
3fff00f0: 00000009 00000001 3fff0f58 40202b55
3fff0100: 00000000 3ffeeea8 3fff1030 4020a508
3fff0110: 0000000a 0000006d 3fff1030 402096ca
3fff0120: 3fff0188 00000001 3ffef070 40206f87
3fff0130: 3ffe0001 00000065 3fff1018 402085c9
3fff0140: 0000003a 3fff02f8 000003e8 3ffef070
3fff0150: 00000009 3ffeeea8 3fff1018 40206fc6
3fff0160: 00000009 3ffeeea8 3fff1018 40207e2f
3fff0170: 3fff01b0 3fff0180 0000000c 3fff1014
3fff0180: 40207add 3fff01e8 3fff019b 3fff0001
3fff0190: 3ffe8440 3fff0101 0afeef40 4020b098
3fff01a0: 3fff1028 3fffc6fc 3ffef280 3fff100c
3fff01b0: 3ffeeea8 00000001 4020a024 3ffeeea8
3fff01c0: 00000009 3fff100c 3ffeeea8 40208212
3fff01d0: 00000003 028c4105 00000002 00000005
3fff01e0: 00000001 3ffef005 00000001 40208c05
3fff01f0: 3fff01d8 3fff01e0 3fff01e8 4020b07e
3fff0200: 402010c2 00000032 3ffef070 00000001
3fff0210: 3ffeeea8 3fff100c 3ffef070 40206ef4
3fff0220: 3fffdad0 3ffef024 3ffeeef0 402087b9
3fff0230: 00000000 00000064 000003e8 3ffef0a4
3fff0240: 00000000 3fff1f54 3ffeeea8 3ffef278
3fff0250: 3fffdad0 3fff0f2c 3ffeeec8 40207aa4
3fff0260: feefeffe 3ffeeed0 00000000 40207b0f
3fff0270: 3fffdad0 00000000 3ffef270 402087e7
3fff0280: feefeffe feefeffe feefeffe 4020a070
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1264, room 16
tail 0
chksum 0x0f
csum 0x0f
~ld

<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 1264, room 16
tail 0
chksum 0x0f
csum 0x0f
~ld
 
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:
AppStart
Connecting to Telecom-59027407
Connected!
My IP Address: 192.168.1.4
FS Initialize result: 1
Total size: 2880 KB
Used size: 1938 KB

[1] [ /frame10.bmp ] 16438 bytes StackBufferUsage: 68
[2] [ /frame100.bmp ] 16438 bytes StackBufferUsage: 76
[3] [ /frame73.bmp ] 16438 bytes StackBufferUsage: 84
[4] [ /frame101.bmp ] 16438 bytes StackBufferUsage: 92
[5] [ /frame89.bmp ] 16438 bytes StackBufferUsage: 100
[6] [ /frame102.bmp ] 16438 bytes StackBufferUsage: 108
[7] [ /frame103.bmp ] 16438 bytes StackBufferUsage: 116
[8] [ /frame104.bmp ] 16438 bytes StackBufferUsage: 124
[9] [ /frame105.bmp ] 16438 bytes StackBufferUsage: 132
[10] [ /frame9.bmp ] 16438 bytes StackBufferUsage: 140
[11] [ /frame106.bmp ] 16438 bytes StackBufferUsage: 148
[12] [ /frame74.bmp ] 16438 bytes StackBufferUsage: 156
[13] [ /frame107.bmp ] 16438 bytes StackBufferUsage: 164
[14] [ /frame108.bmp ] 16438 bytes StackBufferUsage: 172
[15] [ /frame109.bmp ] 16438 bytes StackBufferUsage: 180
[16] [ /frame90.bmp ] 16438 bytes StackBufferUsage: 188
[17] [ /frame11.bmp ] 16438 bytes StackBufferUsage: 196
[18] [ /frame110.bmp ] 16438 bytes StackBufferUsage: 204
[19] [ /frame75.bmp ] 16438 bytes StackBufferUsage: 212
[20] [ /frame111.bmp ] 16438 bytes StackBufferUsage: 220
[21] [ /frame91.bmp ] 16438 bytes StackBufferUsage: 228
[22] [ /frame112.bmp ] 16438 bytes StackBufferUsage: 236
[23] [ /frame113.bmp ] 16438 bytes StackBufferUsage: 244
[24] [ /frame114.bmp ] 16438 bytes StackBufferUsage: 252
[25] [ /frame115.bmp ] 16438 bytes StackBufferUsage: 260
[26] [ /frame92.bmp ] 16438 bytes StackBufferUsage: 268
[27] [ /frame116.bmp ] 16438 bytes StackBufferUsage: 276
[28] [ /frame76.bmp ] 16438 bytes StackBufferUsage: 284
[29] [ /frame117.bmp ] 16438 bytes StackBufferUsage: 292
[45] [ /frame20.bmp ] 16438 bytes StackBufferUsage: 420
[46] [ /frame21.bmp ] 16438 bytes StackBufferUsage: 428
[47] [ /frame22.bmp ] 16438 bytes StackBufferUsage: 436
[48] [ /frame96.bmp ] 16438 bytes StackBufferUsage: 444
[45] [ /frame20.bmp ] 16438 bytes StackBufferUsage: 420
[46] [ /frame21.bmp ] 16438 bytes StackBufferUsage: 428
[47] [ /frame22.bmp ] 16438 bytes StackBufferUsage: 436
[48] [ /frame96.bmp ] 16438 bytes StackBufferUsage: 444
[49] [ /frame23.bmp ] 16438 bytes StackBufferUsage: 452
[50] [ /frame24.bmp ] 16438 bytes StackBufferUsage: 460
[51] [ /frame79.bmp ] 16438 bytes StackBufferUsage: 468
[52] [ /frame25.bmp ] 16438 bytes StackBufferUsage: 476
[53] [ /frame26.bmp ] 16438 bytes StackBufferUsage: 484
[54] [ /frame97.bmp ] 16438 bytes StackBufferUsage: 492
[55] [ /frame27.bmp ] 16438 bytes StackBufferUsage: 500
[56] [ /frame28.bmp ] 16438 bytes StackBufferUsage: 508
[57] [ /frame29.bmp ] 16438 bytes StackBufferUsage: 516
[58] [ /frame98.bmp ] 16438 bytes StackBufferUsage: 524
[59] [ /frame8.bmp ] 16438 bytes StackBufferUsage: 532
[68] [ /frame36.bmp ] 16438 bytes StackBufferUsage: 604
[69] [ /frame80.bmp ] 16438 bytes StackBufferUsage: 612
[70] [ /frame37.bmp ] 16438 bytes StackBufferUsage: 620
[71] [ /frame38.bmp ] 16438 bytes StackBufferUsage: 628
[72] [ /frame39.bmp ] 16438 bytes StackBufferUsage: 636
[73] [ /frame4.bmp ] 16438 bytes StackBufferUsage: 644
[74] [ /frame81.bmp ] 16438 bytes StackBufferUsage: 652
[68] [ /frame36.bmp ] 16438 bytes StackBufferUsage: 604
[69] [ /frame80.bmp ] 16438 bytes StackBufferUsage: 612
[70] [ /frame37.bmp ] 16438 bytes StackBufferUsage: 620
[71] [ /frame38.bmp ] 16438 bytes StackBufferUsage: 628
[72] [ /frame39.bmp ] 16438 bytes StackBufferUsage: 636
[73] [ /frame4.bmp ] 16438 bytes StackBufferUsage: 644
[74] [ /frame81.bmp ] 16438 bytes StackBufferUsage: 652
[83] [ /frame47.bmp ] 16438 bytes StackBufferUsage: 724
[84] [ /frame48.bmp ] 16438 bytes StackBufferUsage: 732
[85] [ /frame49.bmp ] 16438 bytes StackBufferUsage: 740
[86] [ /frame5.bmp ] 16438 bytes StackBufferUsage: 748
[87] [ /frame83.bmp ] 16438 bytes StackBufferUsage: 756
[88] [ /frame50.bmp ] 16438 bytes StackBufferUsage: 764
[89] [ /frame51.bmp ] 16438 bytes StackBufferUsage: 772
[83] [ /frame47.bmp ] 16438 bytes StackBufferUsage: 724
[84] [ /frame48.bmp ] 16438 bytes StackBufferUsage: 732
[85] [ /frame49.bmp ] 16438 bytes StackBufferUsage: 740
[86] [ /frame5.bmp ] 16438 bytes StackBufferUsage: 748
[87] [ /frame83.bmp ] 16438 bytes StackBufferUsage: 756
[88] [ /frame50.bmp ] 16438 bytes StackBufferUsage: 764
[89] [ /frame51.bmp ] 16438 bytes StackBufferUsage: 772
[99] [ /frame6.bmp ] 16438 bytes StackBufferUsage: 852
[100] [ /frame85.bmp ] 16438 bytes StackBufferUsage: 860
[101] [ /frame60.bmp ] 16438 bytes StackBufferUsage: 868
[102] [ /frame61.bmp ] 16438 bytes StackBufferUsage: 876
[103] [ /frame62.bmp ] 16438 bytes StackBufferUsage: 884
[104] [ /frame63.bmp ] 16438 bytes StackBufferUsage: 892
[99] [ /frame6.bmp ] 16438 bytes StackBufferUsage: 852
[100] [ /frame85.bmp ] 16438 bytes StackBufferUsage: 860
[101] [ /frame60.bmp ] 16438 bytes StackBufferUsage: 868
[102] [ /frame61.bmp ] 16438 bytes StackBufferUsage: 876
[103] [ /frame62.bmp ] 16438 bytes StackBufferUsage: 884
[104] [ /frame63.bmp ] 16438 bytes StackBufferUsage: 892
[114] [ /frame70.bmp ] 16438 bytes StackBufferUsage: 972
[114] [ /frame70.bmp ] 16438 bytes StackBufferUsage: 972
[115] [ /frame71.bmp ] 16438 bytes StackBufferUsage: 980
[116] [ /frame72.bmp ] 16438 bytes StackBufferUsage: 988
[117] [ /frame1.bmp ] 16438 bytes StackBufferUsage: 996
[118] [ /frame88.bmp ] 16438 bytes StackBufferUsage: 1004
Closed
 
Top