rpc-service-fs

0
README.md

RPC Service - Filesystem

This service provides an ability to manage device files remotely. It is required by the

mos ls
,
mos get
,
mos put
,
mos rm
commands. If this library is not included in the app, those commands won't work. It is possible to call this service programmatically via serial, HTTP/RESTful, Websocket, MQTT or other transports (see RPC section) or use
mos
tool.

Below is a list of exported RPC methods and arguments:

FS.List

Get device file list. Arguments: none.

Example usage:

mos call FS.List [ "mgos_ro_vars_schema.json", "conf0.json", ... ]

This RPC command has a shortcut:

mos ls
:

mos ls "mgos_ro_vars_schema.json", "conf0.json", ...

FS.ListExt

Same as

FS.List
but also returns extra file info like file sizes. Arguments: none.

Example usage:

mos call FS.ListExt [ { "name": "mgos_ro_vars_schema.json", "size": 332 }, ... ]

This RPC command has a shortcut:

mos ls -l
:

mos ls -l api_adc.js 259 api_arch_uart.js 651 ...

FS.Get

Returns file content. Arguments:

Example usage:

mos call FS.Get '{"filename": "init.js"}' { "data": "bG9hZCgnYXBpX2NvbmZpZ...", # Base64 encoded data "left": 0 # How many bytes left in a file }

This RPC command has a shortcut:

mos get
:

mos get init.js load('api_gpio.js'); ...

FS.Put

Write data into file. Write is done either by overwriting an existing content, or by appending to the existing content. Arguments:

This RPC command has a shortcut:

mos put
. It splits large files into small chunks, and calls
FS.Put
sequentially, appending content.

mos put /etc/passwd foo.txt

FS.Remove

Delete file. Arguments:

This RPC command has a shortcut:

mos rm
:

mos rm foo.txt

FS.Mkfs

Create filesystem. Arguments:

Example usage:

mos call FS.Mkfs '{"dev_type": "spi_flash", "dev_opts": "{\"freq\": 20000000, \"cs\": 0}", "fs_type": "SPIFFS", "fs_opts": "{\"size\": 131072}'

FS.Mount

Mount filesystem. Arguments:

mos call FS.Mount '{"path": "/mnt", "dev_type": "spi_flash", "dev_opts": "{\"freq\": 20000000, \"cs\": 0}", "fs_type": "SPIFFS", "fs_opts": "{\"size\": 131072}"}'

FS.Umount

Unmout filesystem. Arguments:

mos call FS.Mount '{"path": "/mnt"}'