Tag Archives: SPIFFS

Arduino NodeMCU (ESP8266) Spiffs File System Uploading and Reading

In this tutorial we upload a text file and read it in serial monitor.

Steps to Upload a file in NodeMCU SPIFFS file system

ESP8266FS is a tool which integrates into the Arduino IDE. It adds a menu item to Tools menu for uploading the contents of sketch data directory into ESP8266 flash file system.

  • Restart Arduino IDE
  • Open a sketch (or create a new one and save it)
  • Go to sketch directory (choose Sketch > Show Sketch Folder)
  • data older next to your .ino file
  • Create a directory named data and put your files you want in the file system there

  • Make sure you have selected a board, port, and closed Serial Monitor
  • Select Tools > ESP8266 Sketch Data Upload. This should start uploading the files into ESP8266 flash file system. When done, IDE status bar will display SPIFFS Image Uploaded message. Note during upload it takes longer time.

 

Reading Uploaded File

In above process we uploaded notes.txt file in ESP flash. In this program we read it and display its contents in serial monitor. Uploading of sketch will not affect sketch data. i.e. uploaded notes.txt file.

/*
 *  ESP8266 Communication and Protocols
 *  SPIFFS Direct File Upload Example
 *  -Manoj R. Thkuar
 */

#include <ESP8266WiFi.h>
#include <FS.h>   //Include File System Headers

const char* file = "/notes.txt";   //Enter your file name

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();

  //Initialize File System
  SPIFFS.begin();
  Serial.println("File System Initialized");

  File dataFile = SPIFFS.open(file, "r");   //Open File for reading
  Serial.println("Reading Data from File:");
  //Data from file
  for(int i=0;i<dataFile.size();i++) //Read upto complete file size
  {
    Serial.print((char)dataFile.read());    //Read file
  }
  dataFile.close();
}

void loop() {
}

 

Results


In serial monitor you will get File contents, you can upload images, html and javascript files. examples can be found here

  1. Image upload and display
  2. JavaScript Gauges

ESP8266 (ajax) update part of web page without refreshing

In this tutorial we receive ADC data and send LED on off data to ESP8266 without refreshing webpage. You can do a lot of things with this. At the end we will see some advance applications of this. To make this possible we need to use javaScript Ajax.

Tools you need

only NodeMCU, Laptop and USB cable

What you will learn?

  1. ESP8266 Ajax web page update without refresh.
  2. Sending data to ESP NodeMCU without page refresh.
  3. Getting data from ESP8266 NodeMCU without page refresh and update it in web page dynamically. such as ADC values or temperature readings.

Continue reading ESP8266 (ajax) update part of web page without refreshing

Upload image (PNG, JPEG) to ESP8266 Web Page and Display it

ESP8266 NodeMCU can be used as Web server with html webpage. Many times you may want to add images in web page. This can be achieved with help of SPIFFS (SPI Flash File System) or use of dataURL for small size images. Lets see step by step to upload image in web page.

There are two ways to display image in web page.

Continue reading Upload image (PNG, JPEG) to ESP8266 Web Page and Display it

Example of ESP8266 Flash File System (SPIFFS)

This tutorial explains in depth ESP8266 Flash File System Called as (SPIFFS). There are two ways to store data on ESP8266 one is using internal EEPROM which is of 512 Bytes but you can write data 1 millions of times (no file system). and Second is use of SPI Flash (64kBytes to 3Mbyte), when you see ESP-01 a small 8-Pin Chip is present near to the ESP8266 which is FLASH memory connected to ESP through SPI. In this flash memory ESP stores the program. Along with program you can store your files on it. Limitation of this memory is it has only 10000 (ten thousand) write cycles.

Even though file system is stored on the same flash chip as the program, programming new sketch will not modify file system contents. This allows to use file system to store sketch data, configuration files, or content for Web server. Continue reading Example of ESP8266 Flash File System (SPIFFS)