Skip to content

FanatiQS/esp-nvs-js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

60 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ESP32 Non-Volatile Storage reader

A JavaScript browser library for reading ESP32 Non-Volatile Storage (NVS) entries over USB using WebSerial.

Highlights

  • Reads specified NVS partitions or auto-detects them using device's partition table
  • Supports all NVS types (integers, strings, blobs)
  • Communicates directly with the ESP32 over USB using WebSerial
  • Efficiently reads just enough data to find what you are looking for
  • Can retrieve specific entry or get all entries
  • Provides both function-based and class-based interfaces
  • Includes built-in output formats for JSON and HTML
  • Easily customizable output via user-friendly iterator pattern

Browser Support

WebSerial is a non-standard feature and is only supported in Chromium-based browsers. See CanIUse for browser support.

Live Demos

Install

The library can either be downloaded using NPM or loaded on request from a CDN. Local install is only required for full TypeScript types support.

CDN

Import the library from CDN into your JavaScript code like this:

import { NVS } from "https://cdn.jsdelivr.net/gh/FanatiQS/esp-nvs-js@master/nvs.js";

NPM

Install the library through NPM and then import it into your JavaScript code like this:

npm install fanatiqs/esp-nvs-js
import { NVS } from "esp-nvs-js";

Usage

Other than the limited browser support mentioned above, WebSerial also only works on HTTPS/localhost and can only be triggered by a UserGesture, not on load. This means that all examples need to be called from some kind of user input, like a button press or other form of user initiated trigger.

Example 1

Get the value for a specific entry. Look at examples/simple.html (demo) for a complete example.

const nvs = new NVS(await navigator.serial.requestPort());
const chan = await nvs.get("nvs.net80211", "sta.chan");
console.log(chan);

Example 2

Get all values as JSON. Look at examples/json.html (demo) for a complete example.

const nvs = new NVS(await navigator.serial.requestPort());
await nvs.all();
console.log(nvs.toJSON());

Example 3

Render all values in HTML table. Look at examples/table.html (demo) for a complete example.

const nvs = new NVS(await navigator.serial.requestPort());
await nvs.all();
document.body.appendChild(nvs.toHTML());

Example 4

Get all values through iterator.

const nvs = new NVS(await navigator.serial.requestPort());
await nvs.all();
for (const [ namespace, key, value ] of nvs) {
	console.log(namespace, key, value);
}

Limitations

  • No support for encrypted NVS partitions
  • No delete or write support

Todo

  • Add tests
  • Add delete support
  • Add write support
  • Add support for encrypted partitions