ESP32通过程序从闪存文件系统(SPIFFS)读取信息
Posted perseverance52
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ESP32通过程序从闪存文件系统(SPIFFS)读取信息相关的知识,希望对你有一定的参考价值。
ESP32通过程序从闪存文件系统(SPIFFS)读取信息
- 开发板型号: ESP32-Dev-Module
实例程序
#include "SPIFFS.h"
void setup() {
Serial.begin(115200);
if(!SPIFFS.begin()){
Serial.println("初始化SPIFFS失败!");
return;
}
File file = SPIFFS.open("/text.txt");
if(!file){
Serial.println("无法打开文件进行读取");
return;
}
Serial.println("文件内容:");
while(file.available()){
Serial.write(file.read());
}
file.close();
}
void loop() {}
- 在项目文件夹下建立一个
date
文件夹,在里面放置需要上传的文件
- 在date文件夹下,我存放了一个名为:
text.txt
的文件,内容:
{"code":"200","updateTime":"2021-08-24T20:35+08:00","fxLink":"http://hfx.link/3ep1","daily":[{"fxDate":"2021-08-24","sunrise":"06:01","sunset":"18:56","moonrise":"20:21","moonset":"08:23","moonPhase":"Waning gibbous","tempMax":"34","tempMin":"25","iconDay":"305","textDay":"Light Rain","iconNight":"154","textNight":"Overcast","wind360Day":"330","windDirDay":"NW","windScaleDay":"3-4","windSpeedDay":"13","wind360Night":"225","windDirNight":"SW","windScaleNight":"1-2","windSpeedNight":"3","humidity":"96","precip":"1.0","pressure":"990","vis":"24","cloud":"55","uvIndex":"5"},{"fxDate":"2021-08-25","sunrise":"06:01","sunset":"18:55","moonrise":"20:52","moonset":"09:18","moonPhase":"Waning gibbous","tempMax":"31","tempMin":"25","iconDay":"305","textDay":"Light Rain","iconNight":"305","textNight":"Light Rain","wind360Day":"45","windDirDay":"NE","windScaleDay":"1-2","windSpeedDay":"3","wind360Night":"225","windDirNight":"SW","windScaleNight":"1-2","windSpeedNight":"3","humidity":"98","precip":"1.0","pressure":"994","vis":"10","cloud":"55","uvIndex":"9"},{"fxDate":"2021-08-26","sunrise":"06:02","sunset":"18:54","moonrise":"21:23","moonset":"10:12","moonPhase":"Waning gibbous","tempMax":"31","tempMin":"23","iconDay":"305","textDay":"Light Rain","iconNight":"305","textNight":"Light Rain","wind360Day":"45","windDirDay":"NE","windScaleDay":"1-2","windSpeedDay":"3","wind360Night":"180","windDirNight":"S","windScaleNight":"1-2","windSpeedNight":"3","humidity":"97","precip":"5.1","pressure":"996","vis":"17","cloud":"80","uvIndex":"4"}],"refer":{"sources":["Weather China"],"license":["no commercial use"]}}
程序编译和上传文件上传。
-
第一步,程序编译上传。
-
第二步,闪存文件上传。(注意上传闪存文件时,不要打开串口,否则会报错)
-
串口打印读取的闪存文件信息。(连续读取的,信息很长,部分内容截图)
以上是关于ESP32通过程序从闪存文件系统(SPIFFS)读取信息的主要内容,如果未能解决你的问题,请参考以下文章