|
1 | 1 | # Sqlite3 Arduino library for ESP8266 |
2 | | -This library allows you to access SQLite database files from SPIFFS or SD Card through ESP8266 SoC (such as WeMos D1 mini or NodeMCU v1.0. |
| 2 | +This library enables access to SQLite database files from SPIFFS or Micro SD Card through ESP8266 SoC using [WeMos D1 mini](https://wiki.wemos.cc/products:d1:d1_mini) and [Micro SD Card Shield](https://wiki.wemos.cc/products:d1_mini_shields:micro_sd_card_shield) (shown below) or [NodeMCU v1.0](https://en.wikipedia.org/wiki/NodeMCU) with separate MicroSD Module. |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | +## Usage |
| 7 | +Sqlite3 C API such as `sqlite3_open` can be directly invoked. Before calling please invoke: |
| 8 | + |
| 9 | +```c++ |
| 10 | + vfs_mount("/SD0", SS); // for Micro SD Shield |
| 11 | + File db_file_obj_1; vfs_set_spiffs_file_obj(&db_file_obj_1); // For SPIFFS |
| 12 | +``` |
| 13 | +apart from `SPI.begin()` or `SPIFFS.begin()` as appropriate. |
| 14 | +
|
| 15 | +The SS Pin is D8 on the Micro SD Shield for WeMos D1 mini. It can be changed accordingly. |
| 16 | +
|
| 17 | +Please see the examples for full illustration of usage for the two file systems. The databases need to be copied to the Micro SD card root folder before the SD example can be used. Please see the comments section of the example. |
| 18 | +
|
| 19 | +## Installation |
| 20 | +Please download this library, unzip it to the libraries folder of your ESP8266 sdk location. The location varies according to your OS. For example, it is usually found in the following locations: |
| 21 | +``` |
| 22 | +Windows: C:\Users\(username)\AppData\Roaming\Arduino15 |
| 23 | +Linux: /home/<username>/.arduino15 |
| 24 | +MacOS: /home/<username>/Library/Arduino15 |
| 25 | +``` |
| 26 | +Under Arduino15 folder please navigate to `packages/esp8266/hardware/esp8266/<version>/libraries` |
| 27 | +
|
| 28 | +If you do not have the ESP8266 sdk for Arduino, please see http://esp8266.github.io/Arduino/versions/2.0.0/doc/installing.html for installing it. |
| 29 | +
|
| 30 | +## Dependencies |
| 31 | +The SdFat library is required for accessing MicroSD card. This library can be donwloaded from https://github.com/greiman/SdFat. |
| 32 | +
|
| 33 | +The Sqlite3 code is included with the library. |
| 34 | +
|
| 35 | +## Limitations on ESP8266 |
| 36 | +* The default page size of 4096 leads to "Out of memory" as the size increases over 500 records. Please use page size of 512 using the commands `PRAGMA page_size=512; VACUUM;`, if you are planning to use your own sqlite3 files. |
| 37 | +* Inserting records over a 1000 records gives "Out of memory" |
| 38 | +* These problems exist on NodeMCU as well due to low memory on ESP8266 |
| 39 | +* Retrieving from db having 10 million records has been tested. But it needs stack space to be increased to atleast 6144 bytes. Please modify cores/esp8266/cont.h to increase stack size. |
| 40 | +* It takes around 1 second to retrieve from such dataset, even using the index. |
| 41 | +
|
| 42 | +## Limitations of this library |
| 43 | +* Multiple SD Cards can be supported (using multiple CS Pins). But as of now only one SD Card is supported (`/SD0`). |
| 44 | +* Before opening database files from SPIFFS, the `vfs_set_spiffs_file_obj()` should be called with a reference to SPIFFS file object |
| 45 | +* A prefix (in front of filenames) such as `/FLASH/` is to be used for SPIFFS and `/SD0/` is to be used for Micro SD, for opening databases. |
| 46 | +
|
| 47 | +## ESP32 |
| 48 | +
|
| 49 | +This library probably works with ESP32 too. I have not tested it as I don't have ESP32 module. If you test it, would appreciate if you inform me about the results. |
| 50 | +
|
| 51 | +## Acknowledgements |
| 52 | +* This library was developed by modifying the VFS layer developed by [Luiz Felipe Silva](https://github.com/luizfeliperj). The documentation can be found [here](https://nodemcu.readthedocs.io/en/master/en/modules/sqlite3/). |
| 53 | +* The census2000 and baby names databases were taken from here: http://2016.padjo.org/tutorials/sqlite-data-starterpacks/. But no license information is available. |
| 54 | +* The mdr512.db (Million Domain Rank database) was created with data from [The Majestic Million](https://majestic.com/reports/majestic-million) and is provided under CC 3.0 Attribution license. |
| 55 | +* The [ESP8266 core for Arduino](https://github.com/esp8266/Arduino) |
| 56 | +* [The Arduino platform](https://arduino.cc) |
0 commit comments