First off—thank you for your interest! Contributions are very welcome.
This project targets ESP32 + Arduino core and is primarily developed in VS Code using PIOArduino (a fork of PlatformIO).
- Quick start (VS Code + PIOArduino)
- PlatformIO environments
- Filesystem & partitions
- Project constraints & invariants
- Coding style
- Commit messages & branches
- Pull request checklist
- Adding/Running examples
- Reporting bugs & proposing features
- License
- Install VS Code & PIOArduino
- Install the PIOArduino extension (PlatformIO fork) in VS Code.
- Open the project
File → Open Folder…and select the repository root.
- Dependencies
- Handled by PlatformIO (see
platformio.ini). We depend on:- ArduinoJson
- ArduinoStreamUtils
- LittleFS (from ESP32 core, or
lorol/LittleFSif your toolchain does not bundle it)
- Handled by PlatformIO (see
- Select an environment
- Use the VS Code status bar (PlatformIO env selector) to choose your board env (e.g.,
esp32devoresp32-s3).
- Use the VS Code status bar (PlatformIO env selector) to choose your board env (e.g.,
- Build / Upload / Monitor
- Build:
PlatformIO: Build - Upload:
PlatformIO: Upload - Serial Monitor:
PlatformIO: Monitor(or addmonitor_speedinplatformio.ini)
- Build:
A minimal platformio.ini you can adapt:
[env]
framework = arduino
platform = espressif32
build_flags =
-std=gnu++17
-D ARDUINOJSON_USE_LONG_LONG=1
-D ARDUINOJSON_ENABLE_STD_STRING=1
-D ESP_JSONDB_ENABLE_AUTOSYNC=1
monitor_speed = 115200
lib_deps =
bblanchon/ArduinoJson
bblanchon/ArduinoStreamUtils
lorol/LittleFS_esp32 @ ^1.0.6
; ---- Example boards ----
[env:esp32dev]
board = esp32dev
board_build.filesystem = littlefs
build_flags =
${env.build_flags}
-D CONFIG_ARDUHAL_LOG_COLORS=1
[env:esp32s3]
board = esp32-s3-devkitc-1
board_build.filesystem = littlefs
board_build.partitions = partitions.csv ; see the Partitions section
build_flags =
${env.build_flags}
-D BOARD_HAS_PSRAM
-D CONFIG_SPIRAM_SUPPORT=1Tip: Boards with PSRAM are recommended if you plan to store larger documents or many collections.
- Each supported board should have its own
[env:...]with the rightboard,board_build.filesystem, and optionalboard_build.partitions. - Keep common options under the shared
[env]section. - Prefer C++17 via
-std=gnu++17inbuild_flags. - Add feature flags as
-Ddefines (e.g., autosync toggles, debug logs).
- The DB stores documents as MessagePack files in LittleFS under a base directory (e.g.,
/jsondb). - For S3 or projects needing more FS space, commit a custom
partitions.csvand point to it from your env:
Example partitions.csv (adjust to your flash size):
# Name, Type, SubType, Offset, Size, Flags
nvs, data, nvs, 0x9000, 0x5000,
otadata, data, ota, 0xE000, 0x2000,
app0, app, ota_0, 0x10000, 0x190000,
app1, app, ota_1, 0x1A0000,0x190000,
littlefs, data, spiffs, 0x330000,0x0D0000,- You can format LittleFS from a sketch once (e.g.,
LittleFS.format()for dev) or use a simple helper tool. - All LittleFS access in the library must hold the global FS mutex (see constraints).
Please keep these in mind when contributing:
- C++17, no exceptions
- Use explicit status codes via
DbStatus{code, message}andDbResult<T>— do notthrow.
- Use explicit status codes via
- Time sync requirement
- Timestamps are stored in UTC milliseconds. The application (sketch) must call
configTime(...)before creating/updating documents.
- Timestamps are stored in UTC milliseconds. The application (sketch) must call
- Filesystem access is serialized
- LittleFS operations must be guarded by the global FS mutex (use
FrLockwithg_fsMutexwhen touching FS).
- LittleFS operations must be guarded by the global FS mutex (use
- Autosync task (FreeRTOS)
- The DB may run a background task that flushes dirty documents every
intervalMs. Keep callbacks non-blocking; tune stack/priority/core viaESPJsonDBConfig.
- The DB may run a background task that flushes dirty documents every
- On-disk layout & atomic writes
- Documents are saved as
<id>.jdbunder/baseDir/<collection>/. Writes should be atomic: write to*.tmpthenrename().
- Documents are saved as
- Validation hooks
- Collections may have a
Schemavalidator. Mutations should run pre-save validation and fail with a clear status when invalid.
- Collections may have a
- Language/Std: C++17 (embedded-friendly). Prefer
std::unique_ptr,std::vector,std::string. - Error handling: Return
DbStatus/DbResult<T>; never throw. Keep messages short, static strings where possible. - Thread-safety: Guard shared structures with
FrMutex/FrLock. All LittleFS calls must hold the global FS mutex. - I/O: Use
StreamUtils::WriteBufferingStreamfor buffered writes. - Validation: Run schema hooks on create/update; on failure revert and return a validation error.
- Naming: lowerCamelCase for methods/vars, UpperCamelCase for types, ALL_CAPS for simple constants/enums.
- Formatting: Follow the repository
.clang-format+.editorconfigbaseline fromesptoolkit-template(LLVM-derived style,ColumnLimit: 100, tabs with width4,BinPackArguments/Parameters: false,AllowShortFunctionsOnASingleLine: None). - Allocations: Avoid hidden allocations in hot paths and inside event callbacks & sync loops.
- Create feature branches from
dev(e.g.,feat/bulk-update,fix/atomic-write). - Prefer Conventional Commits:
feat: add bulk update with filterfix: guard LittleFS rename with mutexdocs: explain time sync requirementperf: buffer file writes with StreamUtils
- Keep PRs small and focused with a clear description & rationale.
Before opening a PR, verify:
- Builds in PIOArduino for at least one ESP32 board env.
- Examples build (QuickStart, Collections, BulkOperations, etc.).
- No exceptions, no RTTI-specific tricks, no
assert()crashes in production code. - All FS access under the global FS mutex; no races in multi-task contexts.
- Validation hooks called on create/update; failures return a proper status.
- Autosync task (
ESPJsonDBConfig) defaults sane; no blocking inside event callbacks. - Docs updated: README snippets, new example usage if API changed.
- Added/updated an example when introducing a new feature.
- If partitions changed, include
partitions.csvand updateplatformio.ini.
- Examples live under
examples/YourExample/YourExample.ino(Arduino format). - You can also create PlatformIO example projects under
examples/pio/YourExample/with their ownplatformio.iniif needed. - Keep examples small, focused, and runnable:
- Minimal board setup (
Serial, LittleFS begin), DB init withESPJsonDBConfig. - One clear concept (schema validation, bulk updates, references).
- Short serial logs to demonstrate output.
- A header comment with purpose and steps.
- Minimal board setup (
- Bugs: include board model, ESP32 core version, PIOArduino version, and a minimal sketch/project that reproduces the issue.
- Features: describe the use case, constraints, and any API sketches or example code. Be explicit about memory/sync implications.
By contributing, you agree that your contributions will be licensed under the MIT License (same as the project).
Thanks again for helping make esp-jsondb better! 🚀