Skip to content

Commit 61c351c

Browse files
committed
Addressing issue #3
Removed SPIFFS.begin calls in constructors to allow global usage. Updated examples and README to show the need to call SPIFFS.begin
1 parent 6f983cd commit 61c351c

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ Download this file as a zip, and extract the resulting folder into your Arduino
2929
The blog post [ESPFlash: An Arduino Library for Storing Data in the ESP Filesystem](https://dalegi.com/2020/04/22/espflash-an-arduino-library-for-storing-data-in-the-esp-filesystem/) contains some useful comparisons between ESPFlash usage and SPIFFS usage. In addition, here are some basic ESPFlash example:
3030
- Simple ESPFlash integer example - Create ESPFlash instance with file name of "exampleInteger". Set a single elements value, and get it back.
3131
```c++
32+
SPIFFS.begin()
3233
ESPFlash<int> espFlashInteger("/exampleInteger");
3334
espFlashInteger.set(10);
3435
int testInteger = espFlashInteger.get();
3536
```
3637
- Simple ESPFlash vector example - Create ESPFlash instance with file name of "exampleInteger". Append 10 randomly generated elements. Get the elements back.
3738
3839
```c++
40+
SPIFFS.begin()
3941
ESPFlash<int> espFlashInteger("/exampleArray");
4042
for(int ii = 0; ii < 10; ii++)
4143
{
@@ -47,6 +49,7 @@ espFlashInteger.getFrontElements(testGet, sizeof(testGet));
4749
- Simple ESPFlash vector example - Create ESPFlash instance with file name of "exampleInteger". Append 50 randomly generated elements. Get the last 10 elements back.
4850

4951
```c++
52+
SPIFFS.begin()
5053
ESPFlash<int> espFlashInteger("/exampleArray");
5154
for(int ii = 0; ii < 50; ii++)
5255
{
@@ -59,17 +62,19 @@ espFlashInteger.getBackElements(testGet, sizeof(testGet));
5962
- Simple ESPFlashCounter example - Create ESPFlashCounter instance with file name of "exampleCounter". Increment the counter. Get the Counter
6063
6164
```c++
62-
ESPFlashCounter exampleCounter("/exampleCounter");
63-
exampleCounter.increment();
64-
int testGet = exampleCounter.get();
65+
SPIFFS.begin()
66+
ESPFlashCounter exampleCounter("/exampleCounter");
67+
exampleCounter.increment();
68+
int testGet = exampleCounter.get();
6569
```
6670

6771
- Simple ESPFlashString example - Create ESPFlashString instance with file name of "exampleString". Set a string. Get the string.
6872

6973
```c++
70-
ESPFlashCounter exampleString("/exampleString");
71-
exampleString.set("Hello!");
72-
String string = exampleString.get();
74+
SPIFFS.begin()
75+
ESPFlashCounter exampleString("/exampleString");
76+
exampleString.set("Hello!");
77+
String string = exampleString.get();
7378
```
7479
7580
## Further Examples

examples/millisArray/millisArray.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ void setup()
3131
Serial.begin(115200);
3232
Serial.println("Begining millisArray example...");
3333

34+
/* Have to initialise before performing any SPIFFS operations*/
35+
SPIFFS.begin();
36+
3437
for(int ii = 0; ii < 10; ii++)
3538
{
3639
millisArray.append(millis());

examples/powerCycleCounter/powerCycleCounter.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ void setup()
2727
{
2828
Serial.begin(115200);
2929
Serial.println("Starting");
30+
/* Have to initialise before performing any SPIFFS operations*/
31+
SPIFFS.begin();
32+
3033
ESPFlashCounter flashCounter("/counter");
3134
flashCounter.increment();
3235
Serial.print("Power Cycle ESPFlashCounter: ");

examples/ssidStorage/ssidStorage.ino

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ AsyncWebServer server(80);
3636

3737
void setup()
3838
{
39+
/* Have to initialise before performing any SPIFFS operations*/
40+
SPIFFS.begin();
41+
3942
ESPFlashString ssid(SSID_FILEPATH, DEFAULT_SSID);
4043
Serial.begin(115200);
4144
/* Configure access point with static IP address */

src/ESPFlash.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
#ifndef ESPFLASH_H_
2323
#define ESPFLASH_H_
2424

25-
#include <FS.h>
26-
2725
#if defined(ARDUINO_ARCH_ESP32)
2826
#include <SPIFFS.h>
2927
#endif
@@ -99,14 +97,12 @@ class ESPFlash
9997

10098
template<class T> ESPFlash<T>::ESPFlash()
10199
{
102-
SPIFFS.begin();
103100
return;
104101
};
105102

106103
template<class T> ESPFlash<T>::ESPFlash(const char* fileName)
107104
{
108105
setFileName(fileName);
109-
SPIFFS.begin();
110106
return;
111107
};
112108

0 commit comments

Comments
 (0)