Skip to content

Commit 195ea96

Browse files
siara-ccsiara-in
authored andcommittedApr 13, 2019
Change VFS basis to SQLite instead of NodeMCU
1 parent 5e6f00f commit 195ea96

File tree

3 files changed

+550
-555
lines changed

3 files changed

+550
-555
lines changed
 

‎examples/sqlite3_bulk_data_insert/sqlite3_bulk_data_insert.ino

+9-5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <SPI.h>
1616
#include <FS.h>
1717
#include "SD_MMC.h"
18+
#include "SPIFFS.h"
1819

1920
char *dat = NULL;
2021
void block_heap(int times) {
@@ -106,9 +107,9 @@ void displayPrompt(const char *title) {
106107

107108
void displayFreeHeap() {
108109
Serial.printf("\nHeap size: %d\n", ESP.getHeapSize());
109-
Serial.printf("Free Heap: %d\n", esp_get_free_heap_size());
110-
Serial.printf("Min Free Heap: %d\n", esp_get_minimum_free_heap_size());
111-
Serial.printf("Max Alloc Heap: %d\n", ESP.getMaxAllocHeap());
110+
Serial.printf("Free Heap: %d\n", heap_caps_get_free_size(MALLOC_CAP_8BIT));
111+
Serial.printf("Min Free Heap: %d\n", heap_caps_get_minimum_free_size(MALLOC_CAP_8BIT));
112+
Serial.printf("Max Alloc Heap: %d\n", heap_caps_get_largest_free_block(MALLOC_CAP_8BIT));
112113
}
113114

114115
char *random_strings[] = {"Hello world", "Have a nice day", "Testing memory problems", "This should work", "ESP32 has 512k RAM", "ESP8266 has only 36k user RAM",
@@ -121,6 +122,10 @@ int rc;
121122

122123
void setup() {
123124
Serial.begin(115200);
125+
if (!SPIFFS.begin(true)) {
126+
Serial.println(F("Failed to mount file Serial"));
127+
return;
128+
}
124129

125130
randomSeed(analogRead(0));
126131

@@ -139,7 +144,7 @@ void setup() {
139144
void loop() {
140145

141146
// Open database 1
142-
if (openDb("/sdcard/test_bulk_insert.db", &db1))
147+
if (openDb("/sdcard/bulk_ins.db", &db1))
143148
return;
144149

145150
displayFreeHeap();
@@ -209,4 +214,3 @@ void loop() {
209214
input_num();
210215

211216
}
212-

‎examples/sqlite3_console/sqlite3_console.ino

+13-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ int db_open() {
7272
int rc = sqlite3_open(db_file_name, &db);
7373
if (rc) {
7474
Serial.print(F("Can't open database: "));
75+
Serial.print(sqlite3_extended_errcode(db));
76+
Serial.print(" ");
7577
Serial.println(sqlite3_errmsg(db));
7678
return rc;
7779
} else
@@ -91,6 +93,8 @@ int db_exec(const char *sql) {
9193
int rc = sqlite3_exec(db, sql, callback, (void*)data, &zErrMsg);
9294
if (rc != SQLITE_OK) {
9395
Serial.print(F("SQL error: "));
96+
Serial.print(sqlite3_extended_errcode(db));
97+
Serial.print(" ");
9498
Serial.println(zErrMsg);
9599
sqlite3_free(zErrMsg);
96100
} else
@@ -183,7 +187,7 @@ void deleteFile(fs::FS &fs, const char *path) {
183187
}
184188

185189
enum {CHOICE_OPEN_DB = 1, CHOICE_EXEC_SQL, CHOICE_EXEC_MULTI_SQL, CHOICE_CLOSE_DB,
186-
CHOICE_LIST_FOLDER, CHOICE_RENAME_FILE, CHOICE_DELETE_FILE};
190+
CHOICE_LIST_FOLDER, CHOICE_RENAME_FILE, CHOICE_DELETE_FILE, CHOICE_SHOW_FREE_MEM};
187191
int askChoice() {
188192
Serial.println();
189193
Serial.println(F("Welcome to SQLite console!!"));
@@ -199,6 +203,7 @@ int askChoice() {
199203
Serial.println(F("5. List folder contents"));
200204
Serial.println(F("6. Rename file"));
201205
Serial.println(F("7. Delete file"));
206+
Serial.println(F("8. Show free memory"));
202207
Serial.println();
203208
Serial.print(F("Enter choice: "));
204209
return input_num();
@@ -306,8 +311,14 @@ void loop() {
306311
}
307312
}
308313
break;
314+
case CHOICE_SHOW_FREE_MEM:
315+
Serial.printf("\nHeap size: %d\n", ESP.getHeapSize());
316+
Serial.printf("Free Heap: %d\n", esp_get_free_heap_size());
317+
Serial.printf("Min Free Heap: %d\n", esp_get_minimum_free_heap_size());
318+
Serial.printf("Largest Free block: %d\n", heap_caps_get_largest_free_block());
319+
break;
309320
default:
310321
Serial.println(F("Invalid choice. Try again."));
311322
}
312323

313-
}
324+
}

0 commit comments

Comments
 (0)