unbd
- micro implementation of a
network block device
in python.
Use this package for mounting folders on wifi-enabled micropython
devices such as ESP8266
and ESP32
.
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
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.
-
using
snapmount
- Install cpython package on your host computer
pip install git+https://github.com/pulkin/unbd
- Connect your wifi-enabled micropython device to a serial port on your host computer
- Mount your source folder
src
withsnapmount src
Note that
snapmount
uses wifi to communicate host your micropython device in station mode with the host computer. It will attempt to deduce network credentials through Network Manager on Linux (nmcli
). You may explicitly supply credentials through--ssid
and--passphrase
. - Install cpython package on your host computer
-
manually
-
Start NBD server on the host machine
nbd-server 33567 /full/path/to/fs.img -d
-
Connect and install
unbd
on your micropython devicempremote mip install github:pulkin/unbd
-
Mount the remote device
from unbd import connect import os os.mount(connect('host-ip-address', 33567, open=True), "/mount")
Note that
fs.img
located on the host machine contains FAT image. -
- fully virtual file system over wifi
- relatively high performance
- minimal setup needed
- tiny footprint
- no flash storage used (and no performance degradation for intensive IO)
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:
- increase
block_size
(4096 is about the saturated maximum) - ensure the wireless connection is stable
FAT filesystem is, in general, twice as fast as littlefs
for
reading large files.
Case | LittleFS 512 | FAT 512 | FAT 4096 |
---|---|---|---|
App: ~100Kb, tens of source files | 33s | 12s | 9s |
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")
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"