Home

Awesome

build pypi

unbd

unbd - micro implementation of a network block device in python.

What for?

Use this package for mounting folders on wifi-enabled micropython devices such as ESP8266 and ESP32.

Install

If you want to use unbd directly install it on your micropython device through mpremote

mpremote mip install github:pulkin/unbd

To use unbd with cpython and/or in command-line environment use pip

pip install git+https://github.com/pulkin/unbd

How to use

First, install nbd server on your host computer: it will serve file system images over your local network. Then, use the snapmount script on the host or the unbd module on the micropython device directly.

Key features

Performance

The mounted filesystem speeds range from several Kbps up to 100 Kbps in read and write. The final throughput is roughly the ratio block_size / network_latency. Thus, to achieve maximal performance:

FAT filesystem is, in general, twice as fast as littlefs for reading large files.

Real-world benchmarks

CaseLittleFS 512FAT 512FAT 4096
App: ~100Kb, tens of source files33s12s9s

Examples

unbd

Simply mount the partition with default values (micropython)

from unbd import connect
os.mount(connect(host, port, open=True), "/mount")

Mount littlefs with a large block size

os.mount(os.VfsLfs2(connect(host, port, block_size=4096), readsize=4096), "/mount")

Mount FAT with a large block size

os.mount(os.VfsFat(connect(host, port, block_size=4096)), "/mount")

Develop and test with snapmount

See also bare-metal tests for this package.

Running a test script test.py from src

from snapmount import mounted

with mounted('src', endpoint="/", **kwargs) as board:
    out, err = board.exec_raw("import test")
    assert len(err) == 0

Same with snapmount in command line

snapmount src --ssid="ssid" --passphrase="secret" --endpoint=/ --payload="import test"

More options

snapmount src --verbose \
  --ssid="ssid" \
  --passphrase="secret" \
  --soft-reset \ 
  --endpoint=/ \
  --fs=fat \
  --block-size=4096 \
  --payload="import test"

License

LICENSE.md