|
SDK for TESAIoT Dev Kit
API reference & tutorials (ModusToolbox)
|
Functions | |
| void | lfs_wifi_creds_init (void) |
| On this variant a no-op — bento_storage_init() owns bring-up. | |
| void | lfs_wifi_creds_deinit (void) |
| On this variant a no-op; the mtb-mpy teardown ordering does not apply here. | |
| bool | lfs_wifi_creds_ready (void) |
| Forwards to bento_storage_ready(); checked before every read and write. | |
| int | lfs_wifi_creds_read (qspi_wifi_entry_t *entries, int max_entries) |
| Fill the caller's array; returns the entry count, 0 on any validation failure. | |
| bool | lfs_wifi_creds_write (const qspi_wifi_entry_t *entries, int count) |
| Overwrite /.wifi_creds with CRC32; snapshot under the lock, write outside it. | |
| bool | lfs_wifi_creds_needs_resave (void) |
| Always false on this variant — the C store writes only the current format. | |
Six functions over one file, /.wifi_creds on the LittleFS partition: up to QSPI_WIFI_CREDS_MAX (6) entries of qspi_wifi_entry_t (100 bytes, packed: SSID, password, security, flags; declared in wifi_creds_types.h, prototypes in lfs_wifi_creds.h). On the mtb-only variant they are provided by shipped source — template/bento_libs/claw/common/storage_c/lfs_wifi_creds_c.c — which proj_cm33_ns/wifi_init.c and the WiFi worker in sensor_auto_task.c link against. Every exemplar in this family is quoted from those two files, both of which are in the mtb-only zip.
| void lfs_wifi_creds_init | ( | void | ) |
On this variant a no-op — bento_storage_init() owns bring-up.
Initialize LFS credential store. MUST be called from MicroPython task AFTER VFS mount succeeds.
bento_storage_init() owns bring-up, and the store is usable as soon as lfs_wifi_creds_ready() reports the volume mounted. Keep the call where the shared boot code places it so the same source compiles on mtb-mpy, where it is real bring-up that must run from the MicroPython task after the VFS mount with gc_collect() immediately before it. Store init must precede every ready / read / write. Void. | void lfs_wifi_creds_deinit | ( | void | ) |
On this variant a no-op; the mtb-mpy teardown ordering does not apply here.
Invalidate LFS handle before MicroPython soft reset. Called from mpy_main.c before mp_deinit().
wifi_creds_flush_if_dirty() and before gc_sweep_all() destroys the VFS objects; there is no equivalent teardown for the C store because bento_storage stays mounted for the life of the firmware. Void. | bool lfs_wifi_creds_ready | ( | void | ) |
Forwards to bento_storage_ready(); checked before every read and write.
Check if LFS credential store is ready for use.
bento_storage_ready(). Checked before every read and every write at all shipped sites, without exception — read returns 0 and write returns false when not ready, but the guard keeps "store not ready" distinguishable from "no data". Store init must precede it. Cheap; no locking. | int lfs_wifi_creds_read | ( | qspi_wifi_entry_t * | entries, |
| int | max_entries ) |
Fill the caller's array; returns the entry count, 0 on any validation failure.
Read all saved WiFi credentials from LittleFS.
Waits up to 10 seconds for LFS init (VFS mount). Validates magic, version, checksum before returning data.
| entries | Output array (must hold QSPI_WIFI_CREDS_MAX elements) |
| max_entries | Max entries to read |
QSPI_WIFI_CREDS_MAX) and returns the entry count; 0 on any magic, version or checksum failure — no separate error code, and 0 also means an empty file. Validates magic, version and count, then CRC32 with the legacy XOR-32 fallback, then NUL-terminates every SSID and password defensively, exactly as the mtb-mpy reader does. When the target is the shared g_boot_wifi_creds array the call goes under wifi_creds_lock() / wifi_creds_unlock(); the boot read is single-claimer but takes the lock anyway for uniformity (wifi_creds_lock is a no-op before the scheduler starts). Reads through bento_storage_read_file(); any task. | bool lfs_wifi_creds_write | ( | const qspi_wifi_entry_t * | entries, |
| int | count ) |
Overwrite /.wifi_creds with CRC32; snapshot under the lock, write outside it.
Write WiFi credentials to LittleFS.
Creates/overwrites /.wifi_creds with magic + version + entries + checksum.
| entries | Array of entries to write |
| count | Number of entries (1..QSPI_WIFI_CREDS_MAX) |
/.wifi_creds with magic, version, count entries and a CRC32 — always CRC32, never the legacy checksum. Returns bool; on failure the dirty flag is deliberately left set so a later pass retries — never clear g_boot_wifi_creds_dirty around a failed write. The cross-task path on this variant is the opposite of mtb-mpy's: snapshot the globals under the lock, then write outside it, because the flash write takes milliseconds and the BLE worker shares the globals. It runs immediately in the WiFi worker task (compiled only when BENTO_HAS_MPY is 0) — with no VM there is no mpy_main.c and therefore no deferred REPL-idle flusher; the "requires MicroPython task context" wording in lfs_wifi_creds.h is about the Python-VFS store, not this one. Writes through bento_storage_write_file(). sensor_auto_task.c): snapshot under the lock, write outside it, dirty flag cleared only on success. The shipped writer itself:
| bool lfs_wifi_creds_needs_resave | ( | void | ) |
Always false on this variant — the C store writes only the current format.
Check if credentials need re-saving (XOR-32 → CRC32 migration). Call after boot WiFi auto-connect; if true, re-read and re-write.