Skip to content

fix(RegionMap): compact storage /regions3, fix save/load return values, add paged region CLI output#2236

Open
jirogit wants to merge 1 commit intomeshcore-dev:devfrom
jirogit:fix/region-display-paging
Open

fix(RegionMap): compact storage /regions3, fix save/load return values, add paged region CLI output#2236
jirogit wants to merge 1 commit intomeshcore-dev:devfrom
jirogit:fix/region-display-paging

Conversation

@jirogit
Copy link
Copy Markdown

@jirogit jirogit commented Apr 3, 2026

Fixes #1880 – region name memory space max out

Problem

On nRF52840 (T1000-e), the /regions2 binary format used 128 bytes of padding per record:

2 (id) + 2 (parent) + 31 (name) + 1 (flags) + 128 (pad) = 164 bytes/record
32 entries = 5,258 bytes total

This exceeds the available space in nRF52 InternalFS when shared with preferences and identity data. save() would fail silently (hardcoded return true), and on next boot load() would read a truncated file, losing region names beyond ~11 entries.

Additionally, the region CLI command was silently truncated to ~5 entries due to the single-packet reply buffer limit (~161 bytes), making it impossible to verify how many regions were actually stored.

Changes

src/helpers/RegionMap.cpp

  • New /regions3 format: 64-byte padding per record (100 bytes/record, 3,210 bytes for 32 entries = 78% of one 4096B LittleFS block)
  • load() prefers /regions3; falls back to /regions2 (128-byte pad) for automatic migration on next save()
  • After successful save() to /regions3, deletes /regions2 if it exists
  • Fixed save(): hardcoded return truereturn success
  • Fixed load(): hardcoded return truereturn num_regions > 0 || success

examples/simple_repeater/MyMesh.cpp

  • region command now supports paged output:
    • region — first page (wildcard * + entries from index 0)
    • region N — entries from index N onward
    • Footer >N at end of each page indicates the next start index
    • No footer = last page; -none- = no entries at all
  • Fixes silent truncation that limited display to ~5 entries regardless of how many were stored
  • Note: the mobile app UI still shows only ~5 regions due to a separate app-side limitation; that is outside the scope of this fix

Storage size comparison

Format bytes/record 32 entries total nRF52 4096B block usage
/regions2 (old) 164 5,258 B 1.28× ← over limit
/regions3 (new) 100 3,210 B 0.78×

Testing

Tested on Seeedstudio T1000-e:

  • ✅ 32 entries with 29-character names saved and reloaded after reboot
  • region save returns OK
  • region / region 4 / region 8 ... paging works correctly with >N footer
  • ✅ Last page shows no footer
  • ⚠️ Migration from /regions2/regions3 not tested on physical hardware (code path verified by review only)

Fixes #2166

…egion output

- Replace /regions2 (128-byte pad/record, 5258B total) with /regions3
  (64-byte pad/record, 3210B total) to fit within nRF52 InternalFS limits
- Auto-migrate from /regions2 on first save(); delete /regions2 after success
- Fix save() hardcoded 'return true' -> return success
- Fix load() hardcoded 'return true' -> return num_regions > 0 || success
- Add paged output to 'region' CLI command:
  - 'region' shows first page (wildcard + entries from index 0)
  - 'region N' shows entries from index N
  - Footer '>N' indicates next start index; no footer = last page
  - Fixes silent truncation at ~5 entries due to single-packet reply limit
  - Note: mobile app UI still shows only ~5 regions; this is a separate
    app-side issue outside the scope of this fix

Fixes meshcore-dev#1880
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant