ESP32学习笔记:NVS分区永久保存数据

news/2024/10/5 9:21:23

程序示例:

/*ESP32 startup counter example with Preferences library.This simple example demonstrates using the Preferences library to store how many times the ESP32 module has booted. The Preferences library is a wrapper around the Non-volatile storage on ESP32 processor.created for arduino-esp32 09 Feb 2017 by Martin Sloup (Arcao)Complete project details at https://RandomNerdTutorials.com/esp32-save-data-permanently-preferences/
*/#include < Preferences.h >Preferences preferences;void setup() {Serial.begin(115200);Serial.println();// Open Preferences with my-app namespace. Each application module, library, etc// has to use a namespace name to prevent key name collisions. We will open storage in// RW-mode (second parameter has to be false).// Note: Namespace name is limited to 15 chars.preferences.begin("my-app", false);// Remove all preferences under the opened namespace//preferences.clear();// Or remove the counter key only//preferences.remove("counter");// Get the counter value, if the key does not exist, return a default value of 0// Note: Key name is limited to 15 chars.unsigned int counter = preferences.getUInt("counter", 0);// Increase counter by 1counter++;// Print the counter to Serial MonitorSerial.printf("Current counter value: %un", counter);// Store the counter to the Preferencespreferences.putUInt("counter", counter);// Close the Preferencespreferences.end();// Wait 10 secondsSerial.println("Restarting in 10 seconds...");delay(10000);// Restart ESPESP.restart();
}void loop() {}

 

其中几个函数的intro如下:

preferences.begin("my-app", false);

#include < nvs_flash.h >void setup() {nvs_flash_erase(); // 擦除NVS分区nvs_flash_init();  // 初始化NVS分区while(true);
}void loop() {}

 放置一个k-v

获取一个k-v

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hjln.cn/news/44188.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈,一经查实,立即删除!

相关文章

Wireshark基础教程

Wireshark是非常流行的网络封包分析软件,可以截取各种网络数据包,并显示数据包详细信息。常用于开发测试过程各种问题定位。本文主要内容包括: 1、Wireshark软件下载和安装以及Wireshark主界面介绍。 2、WireShark简单抓包示例。通过该例子学会怎么抓包以及如何简单查看分析…

SQL 数据库学习 Part 1

数据和信息 信息 信息是客观存在的,是关于现实世界事物的存在方式或运动状态 数据 数据是用来记录信息的可识别的符号,是信息的具体表现形式 数据和信息的联系数据是信息的符号表示或载体 信息则是数据的内涵,是对数据的语义解释数据库 定义 数据库是长期存储在计算机内、有…

1_JAVA线程

Java 线程 1. 创建和运行线程 1.1 直接使用 Thread 例如: public class ThreadTest {public static void main(String[] args) {Thread t = new Thread() {public void run(){// 要执行的任务System.out.println(Thread.currentThread().getName()+" Running");}};/…

Go变量作用域精讲及代码实战

关注作者,复旦AI博士,分享AI领域与云服务领域全维度开发技术。拥有10+年互联网服务架构、AI产品研发经验、团队管理经验,同济本复旦硕博,复旦机器人智能实验室成员,国家级大学生赛事评审专家,发表多篇SCI核心期刊学术论文,阿里云认证的资深架构师,项目管理专业人士,上…

C# JavaScriptSerializer序列化时的时间处理详解

原文链接:https://www.jb51.net/article/122143.htm输出如下图所示: 猜测这里是由于js初始化时间的时候往往是向 1970/01/01 添加毫秒数,JavaScriptSerializer进行序列化的时候也会格式化为距离1970/01/01 到当该时间点GMT+0 时间的毫秒数, 如果直接反序列化可以看到少了8…

人工智能ChatGPT的多种应用:如何更好地提问

简介 ChatGPT 的主要优点之一是它能够理解和响应自然语言输入。在日常生活中,沟通本来就是很重要的一门课程,沟通的过程中表达的越清晰,给到的信息越多,那么沟通就越顺畅。 和 ChatGPT 沟通也是同样的道理,如果想要 ChatGPT 给到的信息越准确,越清晰,和它的沟通就至关重…

SQLite 自动插入时间戳

CREATE TABLE t1 (id INTEGER PRIMARY KEY,node_addr INT,channel_id INT,value INT,date TIMESTAMP NOT NULLDEFAULT (datetime(now, localtime) ) );

python-识别图片中的文字

1、下载:https://digi.bib.uni-mannheim.de/tesseract/ 我们之所以要应用Tesseract,是因为他是一个开源的OCR(光学字符识别)引擎,它可以从各种图像中提取文本信息。它具有以下作用:- 从扫描或拍摄的图像中提取文本:Tesseract可以从这些非结构化的图像中识别和提取文本,…