ESP8266 SPIFFS FILE SYSTEM UPLOADING AND READING A FILE

Esp8266 have a very good file system. But it is hard for newbies. ;)

So i discovered a way to read files From Spiffs Filesystem.

Esp8266 Repo Did not included the Spiffs Upload Tool which is required for making and uploading Files to Esp8266 FileSystem.

To Upload Files to Spiffs (Esp8266 File System) you need esp8266fs.jar Placed like:

Program files/Arduino/tools/ESP8266FS/tool/esp8266fs.jar

Download: https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.2.0/ESP8266FS-0.2.0.zip

Check Updates: https://github.com/esp8266/arduino-esp8266fs-plugin/releases

这里写图片描述

Next you need to Make New Sketch to test Spiffs:


#include"FS.h"

void setup() {
  Serial.begin(115200);

  bool ok = SPIFFS.begin();
  if (ok) {
    Serial.println("ok");
    boolexist = SPIFFS.exists("/index.html");

    if (exist) {
      Serial.println("The file exists!");

      File f = SPIFFS.open("/index.html", "r");
      if (!f) {
        Serial.println("Some thing went wrong trying to open the file...");
      }
      else {
        int s = f.size();
        Serial.printf("Size=%d\r\n", s);


// USE THIS DATA VARIABLE

        String data = f.readString();
        Serial.println(data);

        f.close();
      }
    }
    else {
      Serial.println("No such file found.");
    }
  }
}


void loop() {
  // put your main code here, to run repeatedly:

}

Now Save your sketch, Go to Sketch Data Folder By Pressing Sketch > Show Sketch Folder

Now add a folder name it “data” without quotes.
这里写图片描述

add some text files in it or make a new one.

(Keep your Baudrate to Highest 921600 if works)

In Arduino Press Tools > Esp8266 Sketch Data Upload

It should upload Spiff files to your esp8266.

It should take some time.

After it completes, Open Arduino Serial Window and then , Upload code to arduino.

Arduino will automatically switch com port to Serial Display when done.

Check your file Contents and Errors.

You can check This inbuilt Sketch too :
这里写图片描述

I have Sucessfully Loaded Data from SPIFFS to OLED using i2c port.

See This :
Documents on SPIFFS: https://github.com/esp8266/Arduino/blob/master/doc/filesystem.md

Making another post for showing complete code. :D

参考网址:

https://www.esp8266.com/viewtopic.php?p=47763

接下来就是编译和烧写了,需要注意的是ESP8266模块,在烧写flash之前需要将GPIO_0接地才能进去正常的烧写模式,具体烧写方法请参考其他帖子。

烧写完成之后,还有一个重要的工作,即烧写文件系统
烧写方法如下:
Uploading files to 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.
Download the tool: https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.2.0/ESP8266FS-0.2.0.zip.
In your Arduino sketchbook directory, create tools directory if it doesn't exist yet
Unpack the tool into tools directory (the path will look like <home_dir>/Arduino/tools/ESP8266FS/tool/esp8266fs.jar)
Restart Arduino IDE
Open a sketch (or create a new one and save it)
Go to sketch directory (choose Sketch > Show Sketch Folder)
Create a directory named data and any 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

GIT上提供了详尽的方法,请参阅 https://github.com/esp8266/Arduino/blob/master/doc/filesystem.md ,
本例中烧写的内容有两部分:
一是config.txt文件,即参数保存与配置;
二是index.html文件,即通过访问192.168.0.1,服务器传给终端的显示页面(类似与登陆路由器之后的登陆界面)。
config.txt采用逗号将ssid / password / api-key / dev_id 分割开:
本例中内容为:360,12345678,60ejo9FrV2328GndsKbQvPURzfYA,762767,

index.html:
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值