Hello amazing people!
when i googled flash memory of nodemcu, i learned it it 4 mb....so i started jumping for 2.8 minutes out of happiness....but when i used eeprom library ,eeprom.begin(), takes the max value of 4096 bytes only....if i try increasing this number, memory outa 4096 still remains unallocated(a result of my few experiments).....now what beauty is there in having 4 mb of flash memory in ma nodemcu board.... could you people please suggest me how can i e able to use all those 4 mb of space in my board...
thanks already
Let's see you code
The "beauty" of all that surplus flash is that, among other things, you can use the SPIFFS file system instead of "EEPROM".
https://tttapa.github.io/ESP8266/Chap11%20-%20SPIFFS.html
i am sorry for being late,actually i am admitted in hospital.....so ya
Let's see you code
#include<EEPROM.h>
void setup() {
Serial.begin(115200); //Serial connection
EEPROM.begin(4096);
}
void loop(){
EEPROM.write(40966,23);
EEPROM.commit();
int x=EEPROM.read(40966);
Serial.println(x);
}
The "beauty" of all that surplus flash is that, among other things, you can use the SPIFFS file system instead of "EEPROM".
A Beginner's Guide to the ESP8266
thanks man.....i just got to that link and was quite useful,but i am a newbie.......however, what i understood is i dont need it......let me explain this bit.....i have a data logger ....when it wont be connecting to internet i want it to save all the readings in its flash memory...so wha t i got from your article of spiffs is that i can save data into flash while uploading......did i understand right?or am i still a moron......
so what else..
Flash memory is not EEPROM memory, they are two different things so the EEPROM libiary will not work on flash memory.
oh damn.....how do i access flash then...
While it is true that the ESP8266 does not have any real EEPROM, a section of flash is reserved for "emulated EEPROM" and a the ESP8266 version of the EEPROM libraries can be used to access it.
You can use the SPIFFS file system for storing data offline just like you can writing to an SD card or EEPROM.
cool...but how?....hold on, why do i use spiffs when flash is 4 mb
thanks for ya reply
sabishaw:
cool...but how?....hold on, why do i use spiffs when flash is 4 mb
thanks for ya reply
Unless you use the flash memory directly (somehow), your choices are limited:
- Emulated EEPROM. This gives you up to 4kBytes. link
- SPIFFS which allows about 3MBytes
means i should go for spiffs....but isnt there a way where i can use all my 4 mbytes....and can i use spiffs the way i wrote in #4....or is it just usable before or while uploading program....
thanks
I sent you a link about SPIFFS before (in a different thread), it is very versatile (more so than EEPROM) since you can both upload files to it using the IDE as that you can create and manage files from within your sketch this is one link and here there is another, SPIFFS is really cool.
thanks man....i will go for em right now
hello again
i used spiffs following the tutorials ya'll suggested...along with the example in ide ESP8233>configfile...
it worked.....but how do i know all the 4 mega bytes are accessible to me.....i cant even think of how can i test.....heres ma code
#include <ArduinoJson.h>
#include "FS.h"
bool loadConfig() {
File configFile = SPIFFS.open("/config.json", "r");
if (!configFile) {
Serial.println("Failed to open config file");
return false;
}
size_t size = configFile.size();
Serial.println("size");
Serial.println(size);
if (size > 10000) {
Serial.println("Config file size is too large");
return false;
}
// Allocate a buffer to store contents of the file.
std::unique_ptr<char[]> buf(new char[size]);
// We don't use String here because ArduinoJson library requires the input
// buffer to be mutable. If you don't use ArduinoJson, you may as well
// use configFile.readString instead.
configFile.readBytes(buf.get(), size);
StaticJsonBuffer<200> jsonBuffer;
JsonObject& json = jsonBuffer.parseObject(buf.get());
if (!json.success()) {
Serial.println("Failed to parse config file");
return false;
}
const char* serverName = json["serverName"];
const char* accessToken = json["accessToken"];
const char* serve = json["serve"];
const char* access = json["access"];
// Real world application would store these values in some variables for
// later use.
Serial.print("Loaded serverName: ");
Serial.println(serverName);
Serial.print("Loaded accessToken: ");
Serial.println(accessToken);
Serial.print("Loade ");
Serial.println(serve);
Serial.print("Loen: ");
Serial.println(access);
return true;
}
bool saveConfig() {
StaticJsonBuffer<200> jsonBuffer;
JsonObject& json = jsonBuffer.createObject();
String k="saadaf";
json["serverName"] = k;
json["accessToken"] = "18888888888888888888888888888888888822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221888888888888888888888888888888822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222221888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888";
json["serve"] = "11111111111111111222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222218888888882222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222218888888888888888888888888888888888888888888888888888888888888888222222222222222222222222222222222222222222222222221888888888888888888888888888888888888888888888888888888888888888822222222222222222222222222222222222222222222222222188888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111";
json["access"] = "22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222188888888888888888888888888888888888888888888888888888888888888882222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222218888888888888888882222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222188888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888";
File configFile = SPIFFS.open("/config.json", "w");
if (!configFile) {
Serial.println("Failed to open config file for writing");
return false;
}
json.printTo(configFile);
return true;
}
void setup() {
Serial.begin(115200);
Serial.println("");
delay(1000);
Serial.println("Mounting FS...");
if (!SPIFFS.begin()) {
Serial.println("Failed to mount file system");
return;
}
if (!saveConfig()) {
Serial.println("Failed to save config");
} else {
Serial.println("Config saved");
}
if (!loadConfig()) {
Serial.println("Failed to load config");
} else {
Serial.println("Config loaded");
}
}
void loop() {
}
When you defined your board type in the Arduino IDE, you had an option to state how much of the flash memory should be dedicated to spiffs. It can’t be the full flash memory because other things are also there, you sketch for example.
To test how much space you have, You can add the “spiffs file upload tool” to the IDE then create a large file of known size on your PC then attempt to upload that. Alternatively, simply keep writing lines of a known size to the spiffs file based on the code you have shown.
FSInfo fs_info;
SPIFFS.info(fs_info);
returns true if the info has been successfully obtained. where
struct FSInfo {
size_t totalBytes;
size_t usedBytes;
size_t blockSize;
size_t pageSize;
size_t maxOpenFiles;
size_t maxPathLength;
};
the FSinfo is a struct, (from the first link)
of course you can set 3M SPIFFS as a maximum on a nodeMCU (1M is minimum for the sketch and other things
When you defined your board type in the Arduino IDE, you had an option to state how much of the flash memory should be dedicated to spiffs. It can't be the full flash memory because other things are also there, you sketch for example.
To test how much space you have, You can add the "spiffs file upload tool" to the IDE then create a large file of known size on your PC then attempt to upload that. Alternatively, simply keep writing lines of a known size to the spiffs file based on the code you have shown.
thanks for our reply.....did you see the line "222222222" in my code.....when i elongated those lines a little more,what i found was that it wouldnt upload to board....then i thought when uploading code, code gets uploaded to 1 M and other 3 M spiffs might be reserved for other files.....also a tutorial on youtube suggests that sketch and json file in flash happen to be saperate and independent of eachother....so that shook my understanding.....in short....i tried elongating the lines in my code,but then it wouldnt upload
thanks
Code: [Select]
FSInfo fs_info;
SPIFFS.info(fs_info);
returns true if the info has been successfully obtained. where
Code: [Select]
struct FSInfo {
size_t totalBytes;
size_t usedBytes;
size_t blockSize;
size_t pageSize;
size_t maxOpenFiles;
size_t maxPathLength;
};
the FSinfo is a struct, (from the first link)
of course you can set 3M SPIFFS as a maximum on a nodeMCU (1M is minimum for the sketch and other things
did you mean believe IDE....i didnt quite understand ....please elaborate a litte
i am a moron at this
sabishaw:
did you mean believe IDE....i didnt quite understand ....please elaborate a litte
i am a moron at this
from within you sketch you can get information about the SPIFFS on your nodeMCU (real time), sort of like a 'properties', using the format described, first creating a variable (of struct-type FSinfo) and then testing to see if it returns true (if (SPIFFS.info(fs_info)) ) and then accessing the field of the variable-(struct) for info.
from within the IDE you set the flash-size and the SPIFFS reserved space. (you know this) 3M SPIFFS is the maximum leaving you 1M for sketch, EEPROM etc.