How to apply a key-value storage database or an embedded key-value storage database in embedded products
[Disclaimer: All Rights Reserved. You are welcome to reprint it. Do not use it for commercial purposes. Contact mailbox: armink.ztl@gmail.com]
1. Background
With the rapid development of the Internet and the arrival of the big data era, NoSQL databases are fully developed with its powerful scalability, efficiency, and real-time performance. The Key-Value storage database is a NoSQL type, and the well-known Redis is an open-source Key-Value storage database developed by C.
At the same time, more and more manufacturers have joined the ranks of IoT products, wearable devices, and smart home embedded product development, and the demand for persistent data storage has become more and more, it is more and more important to select a persistent repository suitable for embedded products with good scalability, low resource occupation, and high stability.
2. EasyFlash
EasyFlashIs an open-source lightweight embedded Flash memory library that provides convenient and common upper-layer application interfaces for MCU. It provides three main functions: Env (environment variable) IAP (online upgrade) and Log (Flash storage Log ). This section describes how to Env a small key-value storage database for Flash.
3. add, delete, modify, and query
In order to call common interfaces of environment variables through the console (terminal), the process of creating, saving, modifying, and deleting the environment variable "temp" is demonstrated. These interfaces can be directly called by the application layer.
The EasyFlash Environment Variable Function API is located at https://github.com/armink/easyflash/blob/master/docs/zh/api.md41012-environmental variable.
The main usage is as follows:
/* Create an environment variable named temp and assign the initial value "123" */flash_set_env ("temp", "123 "); /* change the environment variable temp to "456" */flash_set_env ("temp", "456 "); /* read the temp value of the environment variable */char * temp = flash_get_env ("temp");/* Delete the environment variable temp */flash_set_env ("temp ","");
4. Use Cases
At present, I have applied EasyFlash to store the following content:
- 1. Product power-on operation parameters;
- 2. Operation records;
- 3. editable parameters;
- 4. System Crash logs such as software assertions and hardware exceptions;
- 5. interaction parameters between Bootloader and APP during online upgrade;
- 6. More storage contents need to be explored ......
5. Demo
Currently, the hardware platform has been transplanted to the stm32f10x and stm32f4xx Flash series, and supports bare metal and RT-Thread embedded operating systems. WelcomeStar and pull requestAnd provide more platform support and opinions.
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.