thebigpotatoe / effortless-spiffs Goto Github PK
View Code? Open in Web Editor NEWA class designed to make reading and storing data on the ESP8266 and ESP32 effortless
License: MIT License
A class designed to make reading and storing data on the ESP8266 and ESP32 effortless
License: MIT License
Effortless_SPIFFS when starts removes all files from spiffs on the ESP.
Environment
PlatformIO
thebigpotatoe/Effortless-SPIFFS@^2.3.0
Desktop (please complete the following information):
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Effortless_SPIFFS when starts clear the spiffs on the ESP i suppose.
Is your feature request related to a problem? Please describe.
The flash memory in the ESP32 has a limited lifetime, if we write to it in a frequent loop we could kill it in less than a year.
Describe the solution you'd like
It would be nice if I could write a value to spiffs but "queue it" up for a later time. If the same value is "written" multiple times then the queue would just write the latest value. You should be able to set the max delay via a define or something similar.
Describe alternatives you've considered
n/a
The SPIFFS filesystem is deprecated and not being supported by upstream anymore:
https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html#spiffs-deprecation-warning
Aside from the relatively simple task of search/replacing SPIFFS.
with LittleFS.
you might consider updating the library's name or some function names. Perhaps "eLittleFS" for the class or "EespFS."
Hi! Is there any method for delete a file?
Thank you.
What is the reason of using LittleFS instead of SPIFF for ESP8266?
I have encounter problem in parsing Json using SPIFF with large data. and while searching for solution i found your library.
do you have explanation why to use LittleFS?
#if defined(ESP8266)
#include <LittleFS.h>
Reading/writing to an SD card would be nice (or maybe as an example).
When trying to open a file and dump the contents to the Serial output, a crash occurs if the filesize is too large. In my case it was about 6kB. Running on an ESP32 in Arduino framework.
Function snippet that broke:
fileSystem.openFromFile(filename, payload);
Serial.print("File contents: \n"); Serial.println(payload);
Since I'm still in development, I dump my file to the Serial port at every boot. Once the file grew too large, I got stuck in a reboot/crash loop until I wiped the filesystem.
I think I had plenty of heap available (but my heap debug prints were off), but still hit this wall.
Any way to open a SPIFFS file as a stream instead of a String, etc.?
My intention is that getting WiFi SSID & password (currently hardcoded in code itself) and store it in filesystem and should use the same from next boot onwards. You can see the log that getting last PASSWORD updated value for SSID & PASSWORD too as 'test_passwdtest_passwd12@123'
_fileSystem.openFromFile("/ssid.txt", wifi_ssid);//Issue: getting WiFi password here
fileSystem.openFromFile("/password.txt", wifi_passwd);//getting WiFi password here
Serial.println("FS WiFi details after update");
Serial.println(wifi_ssid);
Serial.println(wifi_passwd);
setup_wifi(wifi_ssid, wifi_passwd);_
Code:
#include <ESP8266WiFi.h>
#include <Effortless_SPIFFS.h>
char *ssid_sta;
char *password_sta;
char* wifi_ssid;
char* wifi_passwd;
// Create fileSystem
eSPIFFS fileSystem;
bool writeToFlash = false; // default value will be overriden by opening file
int run_loop = 0;
void setup() {
delay(3000);
Serial.begin(115200);
Serial.println();
// Check Flash Size - Always try to incorrperate a check when not debugging to know if you have set the SPIFFS correctly
if (!fileSystem.checkFlashConfig()) {
Serial.println("Flash size was not correct! Please check your SPIFFS config and try again");
delay(1000);
ESP.restart();
}
// This will change value through reboots
fileSystem.openFromFile("/writeToFlash.txt", writeToFlash); // This will open the value of writeToFlash
password_sta = (char *) malloc(100);
ssid_sta = (char *) malloc(100);
//Actual: Get it from user webpage; hardcode for now
String input_message;
input_message = "test12 wifi detected!!!";
strcpy(ssid_sta, input_message.c_str());
input_message = "test_passwdtest_passwd12@123";
strcpy(password_sta, input_message.c_str());
}
void setup_wifi(char *ssid_sta, char *password_sta) {
static int count = 0;
// We start by connecting to a WiFi network
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid_sta);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid_sta, password_sta);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
//Serial.print(".");
count++;
if (count == 20)
return;
}
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void loop() {
if (writeToFlash == false) {
Serial.println("Looks like WiFi credentials are entered! or already stored in flash");
fileSystem.openFromFile("/ssid.txt", wifi_ssid);
fileSystem.openFromFile("/password.txt", wifi_passwd);
Serial.println("Local WiFi details");
Serial.println(ssid_sta);
Serial.println(password_sta);
Serial.println("FS WiFi details");
Serial.println(wifi_ssid);
Serial.println(wifi_passwd);
setup_wifi(ssid_sta, password_sta);
{
IPAddress ipAddr = WiFi.localIP();
if (ipAddr[0] != 0) {
Serial.println("IP address is detected!");
writeToFlash = true;
if (fileSystem.saveToFile("/writeToFlash.txt", writeToFlash))
Serial.println("Successfully wrote writeToFlash data to file");
wifi_ssid = ssid_sta;
wifi_passwd = password_sta;
Serial.println("FS WiFi details before reboot");
Serial.println(wifi_ssid);
Serial.println(wifi_passwd);
if (fileSystem.saveToFile("/ssid.txt", wifi_ssid))
Serial.println("Successfully wrote wifi_ssid data to file");
if (fileSystem.saveToFile("/password.txt", wifi_passwd))
Serial.println("Successfully wrote wifi_passwd data to file");
ESP.restart();
}
}
} else if (run_loop == 0) {
fileSystem.openFromFile("/ssid.txt", wifi_ssid);
fileSystem.openFromFile("/password.txt", wifi_passwd);
Serial.println("FS WiFi details after update");
Serial.println(wifi_ssid);
Serial.println(wifi_passwd);
setup_wifi(wifi_ssid, wifi_passwd);
run_loop = 1;
}
}
Log:
Looks like WiFi credentials are entered! or already stored in flash
Local WiFi details
test12 wifi detected!!!
test_passwdtest_passwd12@123
FS WiFi details
Connecting to test12 wifi detected!!!
WiFi connected
IP address:
192.168.0.184
IP address is detected!
Successfully wrote writeToFlash data to file
FS WiFi details before reboot
test12 wifi detected!!!
test_passwdtest_passwd12@123
Successfully wrote wifi_ssid data to file
Successfully wrote wifi_passwd data to file
ets Jan 8 2013,rst cause:2, boot mode:(3,6)
load 0x4010f000, len 3460, room 16
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4
tail 4
chksum 0xc9
csum 0xc9
v0004a6a0
~ld
FS WiFi details after update
test_passwdtest_passwd12@123
test_passwdtest_passwd12@123
Connecting to test_passwdtest_passwd12@123
is it possible to append to a file?
I assume reading from the file, concatenating, and writing would work, but seems heavy duty, especially for larger files.
This lib will be a great choose to my wifi radio project to store/change url-s, but i have trouble to store more String. I have altered example so:
#include <Effortless_SPIFFS.h>
eSPIFFS fileSystem;
String Station1;
String Station2;
void setup(){
Serial.begin(115200);
Station1 = "http://retro.dancewave.online/retrodance.mp3";
Station2 = "http://live.topfm.hu:8000/radio.mp3";
// Write the data back to the SPIFFS
if (fileSystem.saveToFile("/configuration.txt", Station1)) {
Serial.println("Successfully wrote data to file");
}
if (fileSystem.saveToFile("/configuration.txt", Station2)) {
Serial.println("Successfully wrote data to file");
}
}
void loop() {
if (fileSystem.openFromFile("/configuration.txt", Station1)) {
Serial.print("Station1 url:");
Serial.println(Station1);
}
delay(1000);
if (fileSystem.openFromFile("/configuration.txt", Station2)) {
Serial.print("Station2 url:");
Serial.println(Station2);
}
delay(1000);
}
I wait to receive both Station 1 and Station2, but just receive only the second one:
19:43:16.441 -> Station1 url:http://live.topfm.hu:8000/radio.mp3
19:43:17.430 -> Station2 url:http://live.topfm.hu:8000/radio.mp3
19:43:18.423 -> Station1 url:http://live.topfm.hu:8000/radio.mp3
19:43:19.428 -> Station2 url:http://live.topfm.hu:8000/radio.mp3
Library allows store only one String variable?
Hello,
I'm trying to use this tool to store values such as MQTT server address in my ESP8266 Wemos D1 Mni. But when I run the fileSystem.saveToFile("somefile.txt", "21342314"), it always returns Fale.
I've tried to send a String, char, char*, etc and it's all the same result. False. So I tried manually writing the string as per the above example and it also just returns False and no the it's stored (I think).
Any idea what's happening?
When I try to safe String or bool values, I also get these compilation errors:
I'm a noob C++ coder. So I wouldn't be surprised if I'm doing something obvious wrong. I'd appreciate if you could point out my mistake if you see any.
thanks
Hi @thebigpotatoe,
Great work on the library!
I have two feature requests.
Keep it up!
The getting starting example lack of example related to writing a large array of records and reading such.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.